Hi Marc,
I'm a little late to this but thought i'd share my solution in case its of
any help.
First, I create a component that extends ModelGlue's event context to
provide a renderTemplate method.
component extends="ModelGlue.gesture.eventrequest.EventContext" {
/**
* renders a view template and returns its html,
* template: the view template to render
* values: struct of values passed to the view, in addition to the
eventcontext
* name: if provided the output will be added to the viewcollection
*/
function renderTemplate(template, values={}, name="") {
var view = new ModelGlue.gesture.eventhandler.View();
view.template = arguments.template;
for(var key in values) {
var value = new ModelGlue.gesture.eventhandler.Value();
value.name = key;
value.value = values[key];
view.addValue(value);
}
var content = variables._viewRenderer.renderView(this, view,
variables._helpers);
if(len(name)) {
this.getViewCollection().addRenderedView(name, content);
}
return content;
}
}
Then tell ModelGlue to use your component using a little bit of config in
your apps ColdSpring.xml
<bean id="modelglue.eventContextFactory"
class="ModelGlue.gesture.eventrequest.EventContextFactory">
<property name="modelGlue"><ref bean="modelglue.ModelGlue"/></property>
<property name="statePersister"><ref
bean="modelglue.statePersister"/></property>
<property name="viewRenderer"><ref
bean="modelglue.viewRenderer"/></property>
<property name="beanPopulator"><ref
bean="modelglue.beanPopulator"/></property>
<property name="logWriter"><ref bean="modelglue.logWriter"/></property>
<property name="objectPath"><value>com.myapp.MyEventContext
</value></property>
</bean>
Replacing com.myapp.MyEventContext with the path to your new component.
Then in your controller you can call renderTemplate, heres a contrived
example.
function sendSomeEmails(event) {
var users = beans.userservice.getSomeUsersAsArray();
for(var user in users) {
var html = event.renderTemplate("emails/some_notification.cfm",
{user=user});
beans.emailservice.send(body=html, to=user.getEMail());
}
}
I've found this to be a useful solution allowing you to reuse views for
emails
Cheers, Chris
On 28 March 2012 17:41, marc <[email protected]> wrote:
> Hi,
>
> Currently I send an email by specifying an e-mail template in the <view>
> section of my event-handler xml.
> This email-template contains my html, links to graphics,css includes etc
> in a <cfsavecontent> block. Below that block I use a <cfmail> tag that has
> the value of the <cfsavecontent> as the emailbody. So trhe email gets sent
> from a view. Rather kludgy but it works.
>
> Now I want to send e-mails from within a loop, that is in a controller.
> The previous method is not usable here. Is the following possible:
>
> within every the loop iteration
> set text in the event scope - event.setvalue("text",<emailtext>);
> render a view (or multiple views in case of layouts) The views access the
> keys set in the loop;
> use that rendered html as the body of the <cfmail> tag
>
> So I can send multiple emails from within the controller, just have to
> specify a special email layout.
>
> I hope this is clear.
>
> Most likely this is possible but I can't find examples or entries in the
> howto that describe this.
>
> Thanks,
>
> Marc
>
> --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en