Email Layout

30 views
Skip to first unread message

John Whish

unread,
Dec 1, 2009, 11:31:20 AM12/1/09
to ColdBox Platform
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:

<cfcomponent>
<cfproperty name="MailService" type="coldbox:plugin:MailService"
scope="instance">
<cffunction name="sendEnquiry">
<cfset instance.MailService.newMail()>

<cfset email.setLayout( "enquiry" )>
<cfset email.setBody( "Some content here" )>
.. set other properties...

<cfset instance.MailService.send( email )>
</cffunction>
</cfcomponent>

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.

Thanks,
-John

Jason Durham

unread,
Dec 1, 2009, 11:58:52 AM12/1/09
to col...@googlegroups.com
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
in?
> --
> You received this message because you are subscribed to the Google Groups "ColdBox: A ColdFusion Framework" group.
> To post to this group, send email to col...@googlegroups.com
> To unsubscribe from this group, send email to coldbox-u...@googlegroups.com
> For more options, visit this group at http://groups-beta.google.com/group/coldbox
> For more information, visit http://www.luismajano.com/projects/coldbox
> For Documentation, visit http://ortus.svnrepository.com/coldbox/trac.cgi



--
Jason Durham

John Whish

unread,
Dec 1, 2009, 12:40:37 PM12/1/09
to col...@googlegroups.com
Thanks Jason,

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.

Luis Majano

unread,
Dec 1, 2009, 1:35:09 PM12/1/09
to col...@googlegroups.com
Hi,

You can use rendering of layouts by using the renderLayout() method in the renderer plugin. You can do something like this:

Email.Layout.cfm
<html>
my layout
<!--- content will be rendered here --->
<cfoutput>#renderView(view=rc.emailView)#</cfoutput>
</html>


Then in your handlers you can do this:
function sendEmail(){
 
 // 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:
#renderView(arguments.view)#

That's it!

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com


John Whish

unread,
Dec 2, 2009, 4:02:37 AM12/2/09
to col...@googlegroups.com
Thanks Luis,

> 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:
#renderView(arguments.view)#

That would be sweet!

:)
Reply all
Reply to author
Forward
0 new messages