| | 1 | = Quickstart 6: Adding a Site-Wide Template = |
| | 2 | |
| | 3 | In Quickstart 5, we looked at how <result> tags with a NAME attribute can be used to conditionally run other event handlers. |
| | 4 | |
| | 5 | However, what if we always want to run an additional event handler? Easy: don't give it a NAME attribute. |
| | 6 | |
| | 7 | 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>. |
| | 8 | |
| | 9 | The include, though, is special. Open it up. (/translator/views/dspTemplate.cfm). |
| | 10 | |
| | 11 | See Line !#13? "viewcollection.getView('body')"? What's with that? |
| | 12 | |
| | 13 | 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. |
| | 14 | |
| | 15 | 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. |
| | 16 | |
| | 17 | If only we could tell Model-Glue to run the view.template event handler after translationForm and translationFormAction. |
| | 18 | |
| | 19 | 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. |
| | 20 | |
| | 21 | Instead, we can use an ''unnamed'' result. Any unnamed result is considered "implicit," and will always be executed. |
| | 22 | |
| | 23 | 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: |
| | 24 | |
| | 25 | {{{ |
| | 26 | <result do="view.template" /> |
| | 27 | }}} |
| | 28 | |
| | 29 | 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! |