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
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There is a huge demand for CodeIgniter among the PHP web developers due to its dynamic features and benefits these days. It is one of most popular and agile open source PHP framework for creating robust web applications in PHP web development field.…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

729 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