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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 count occurrences of each item in an array.

911 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

21 Experts available now in Live!

Get 1:1 Help Now