Hi, is there a way to specify a template for an email, in the same way
that you can define layouts for output to the browser. It would be
sweet if you could do something like:
<cfproperty name="MailService" type="coldbox:plugin:MailService"
<cfset email.setLayout( "enquiry" )>
<cfset email.setBody( "Some content here" )>
.. set other properties...
<cfset instance.MailService.send( email )>
The setLayout method would get the layout file from the layouts
directory (as defined in the ColdBox config) and wrap the text passed
to the setBody method.
I don't see why you couldn't. Are all emails going to share the same
layout, or might different emails require specific layouts? Can't you
also set layouts based upon the directory the emails views are located
For the app I’m building then their is one email template, but I can see situations where I could want more. At the moment I’m doing the following in my handler:
rc.bodyhtml = getPlugin( ‘renderer’ ).renderView( ‘tags/email/html’ );
rc.bodyplain = getPlugin( ‘renderer’ ).renderView( ‘tags/email/plain’ );
instance.NotificationService.SendEnquiry( rc );
which works fine, however, it says in the docs ( http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbLayoutsViewsGuide )
Important: I do not encourage the overuse of content variables as I see them as performance bottlenecks. As best practice, please use them sparingly.
So, I’m a bit reticent to do it this way and wondered what others did, or even better if the ColdBox MailService could be used with layouts.
You can use rendering of layouts by using the renderLayout() method in the renderer plugin. You can do something like this:
Then in your handlers you can do this:
// set email view
rc.emailView = “emails/customerEmail”;
// render body with layout and custom view
body = getPlugin(“Renderer”).renderLayout(“Email.Layout”);
That’s it. this way, you can use rendering of layouts and views a-la-carte. The key is passing the “renderview()” the custom views you like to render in that layout.
I am thinking for 3.0.0 to make this easier by adding a “view” argument to the renderlayout() method and then in your layouts, you would only need to do:
Luis F. Majano
Ortus Solutions, Corp
ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
IECFUG Manager: http://www.iecfug.com