Renderer Issue - DI vs getPlugin('Renderer')

Hi folks,

I’m running into an issue with the renderer plugin. I have an interception point which sends out and email and I have injected the renderer plugin like so:

/** Inject the ColdBox Renderer Plugin */
property name=“renderService” inject=“coldbox:plugin:Renderer”;

//set email view
rc.emailView = “emails/user_welcome”;
rc.emailBody = renderService.renderLayout(“Layout.Email”);

Layout.Email has a simple output of #rc.emailView# to drop in the email contents.

When I run the above code using the injected renderService I get an error saying that rc.emailview is undefined.

However when I run the following it works without issue.

rc.emailView = “emails/user_welcome”;
rc.emailBody = getPlugin(‘Renderer’).renderLayout(“Layout.Email”);

I would prefer to use the DI approach as it would save a bit of overhead compared to loading the plugin on demand. Does anyone know what might be causing this issue?



In ColdBox 3, the renderLayout methgod accepts a view argument liek so:

rc.emailBody = getPlugin( "Renderer" ).renderLayout(
layout="Layout.Email", view="tags/email/enquiry" );

then in your Layout.Email.cfm you can do:

#renderView( arguments.view )#

- John

thanks John, Good to know.

In some of my emails view I have logic based on certain RC variables existing or not.
I am able to read the rc variables if I use this:

local.htmlview = getPlugin(‘Renderer’).renderLayout(layout="#rc.partnerkey#/Layout.#rc.partnerkey#.Email",view="#rc.mailView#");

however they are undefined if I use:

local.htmlview = renderService.renderLayout(layout="#rc.partnerkey#/Layout.#rc.partnerkey#.Email",view="#rc.mailView#");

where “renderService” is the DI Injected renderer plugin.

Using the getPlugin(‘Renderer’) approach works fine however I was hoping to achieve the same result by with the DI injected renderer. Thoughts?




The difference is that the renderer plugin is transient as it needs to
be to provide thread safety for renderings. So wiring will only work
for that same request only. Then the RC and prc scopes are stale. I
would recommend using it as a provider instead. Use a provider

Thanks Luis. I will try that approach.

Nolan Dubeau

Load *.*,8,1

You need to use

Var rc = event.getCollection()

Or get a handle to the controller to then get the collection, setting the vars without doing this will give you that error.


Andrew Scott