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
332 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
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 look for a specific file type in a local or remote server directory using PHP.

776 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