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:
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
in?
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:
You can use rendering of layouts by using the renderLayout() method in the renderer plugin. You can do something like this:
Email.Layout.cfm
my layout
#renderView(view=rc.emailView)#
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)#
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)#