Solved

Why, when using onBeforeWrite in a SilverStripe object class to send an email using a template, isn't the template found?

Posted on 2014-11-02
1
310 Views
Last Modified: 2014-11-09
When I try to do the above, I get the error "Warning at framework/view/SSViewer.php line 780: None of these templates can be found in theme 'mytheme'" and the template fails to be loaded.

It seems that when I use:
                  $email->setTemplate("MyTemplate");
It is looking somewhere else for the template and not finding it. I have 5 other cases where emails are being sent successfully, and in all other cases, the code is in a controller rather than a dataobject.

I'm fairly new to SilverStripe, so perhaps I'm putting the code in the wrong place. The underlying requirement is that I need to override the onBeforeWrite function for a dataobject so that it sends an email in some circumstances. Perhaps the email sending could be done from something other than my dataobject?

The permissions of the template in question are the same as all the other templates that work, and I have done a ?flush=all and deleted the silverstripe files from /tmp/...
0
Comment
Question by:Terry Woods
1 Comment
 
LVL 35

Accepted Solution

by:
Terry Woods earned 0 total points
ID: 40431830
Apparently the admin pages don't see the templates within the theme folder, which is odd given the error message specifically mentions the correct theme. I tried putting the templates I needed within the mysite/templates folder but that was going to mean I would need to create 2 copies of 2 sub-templates, which isn't DRY enough for my liking. I did try it but from memory had trouble getting the sub-templates to be found too.

I ended up working around the issue by creating a blank front end page, hidden from the menu, that sends emails when loaded. I'll call it regularly with cron.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to dynamically set the form action using jQuery.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now