Quickstart 6: Adding a Site-Wide Template

In Quickstart 5, we looked at how <result> tags with a NAME attribute can be used to conditionally run other event handlers.

 

However, what if we always want to run an additional event handler?  Easy:  don't give it a NAME attribute.

 

If you look at your ModelGlue.xml file, there's an event handler named "view.template."  It doesn't do much:  no messages, no results, just a single <include>.

 

The include, though, is special.  Open it up.  (/translator/views/dspTemplate.cfm).

 

See Line #13?  "viewcollection.getView('body')"?  What's with that?

 

Model-Glue makes it easy to display the rendered HTML from one view inside of another.  In all of your .CFM view templates, a variable named "viewcollection" is available.  To display the rendered HTML from a prior view, simply run getView(), passing it the value of the desired view's NAME attribute.

 

In English:  because we named our <include> for frmPhrase.cfm and dspPhrase.cfm "body", we could use this event-handler to display a "wrapper" around their content.

 

If only we could tell Model-Glue to run the view.template event handler after translationForm and translationFormAction.

 

Well, we could use a result tag, give it a name of "doTemplate," and always add the result in a Controller function.  But that'd be tedious.

 

Instead, we can use an unnamed result.  Any unnamed result is considered "implicit," and will always be executed.

 

So, if we add the following <result> tag to our ModelGlue.xml event handlers for the translation form and its action page, we can cause the view.template event handler to execute:

 

<result do="view.template" />

 

I'd show you the XML, but I did say there was a quiz at the end.  When you've added the result and gotten the sitewide template to work, you've finished the Quickstart!