Changes between Version 8 and Version 9 of QuickStart/6:AddingaSiteWideTemplate

Show
Ignore:
Timestamp:
12/31/09 02:55:09 (16 years ago)
Author:
cfgrok (IP: 64.30.223.5)
Comment:

Switched example to use event types

Legend:

Unmodified
Added
Removed
Modified
  • QuickStart/6:AddingaSiteWideTemplate

    v8 v9  
    11= Quickstart 6: Adding a Site-Wide Template = 
    22 
    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 "template.main". 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/templates/main.cfm). 
     3Model-Glue ships with a default template, which is really just another view file. This view, though, is special. Open it up. (/translator/views/templates/main.cfm). 
    104 
    115See Line !#16? 'viewCollection.getView("body")'? What's with that? 
     
    1711If only we could tell Model-Glue to run the view.template event handler after translationForm and translationFormAction. 
    1812 
    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. 
     13The easiest way to accomplish this is to use an '''event type''' to apply the template to individual event-handlers. You can think of event types as a way to create "shared" XML blocks that are applied to event-handlers either before, after, or before and after the event-handler's own XML. 
    2014 
    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: 
     15In order to add an event type to our event-handlers, we first need to add it to the <event-types> block, so it looks like this: 
    2416 
    2517{{{ 
    26 <result do="template.main" /> 
     18 
     19<event-types> 
     20    <event-type name="templatedPage"> 
     21    </event-type>        
     22</event-types> 
     23 
    2724}}} 
    2825 
    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! 
     26Next, we indicate that we want to add some common functionality that will occur after our event-handler is processed: 
     27 
     28{{{ 
     29 
     30<event-types> 
     31    <event-type name="templatedPage"> 
     32        <after> 
     33        </after> 
     34    </event-type>        
     35</event-types> 
     36 
     37}}} 
     38 
     39Then we add our template view to the event type: 
     40 
     41{{{ 
     42 
     43<event-types> 
     44    <event-type name="templatedPage"> 
     45        <after> 
     46            <views> 
     47                <include name="main" template="templates/main.cfm" /> 
     48            </views> 
     49        </after> 
     50    </event-type>        
     51</event-types> 
     52 
     53}}} 
     54 
     55Finally, we use the "type" attribute of the event-handler tag to apply the new type to our events, so they now look like this: 
     56 
     57{{{ 
     58 
     59<event-handler name="translationForm" type="templatedPage"> 
     60    <views> 
     61        <include name="body" template="frmPhrase.cfm"> 
     62            <value name="xe_translate" value="translationFormAction" /> 
     63        </include> 
     64    </views> 
     65</event-handler> 
     66 
     67<event-handler name="translationFormAction" type="templatedPage"> 
     68    <broadcasts> 
     69        <message name="NeedTranslation" /> 
     70    </broadcasts> 
     71    <views> 
     72        <include name="body" template="dspPhrase.cfm"> 
     73            <value name="xe_translationForm" value="translationForm" /> 
     74        </include> 
     75    </views> 
     76    <results> 
     77        <result name="ValidationError" do="translationForm" redirect="true" /> 
     78    </results> 
     79</event-handler> 
     80 
     81}}} 
     82 
     83[http://localhost/translator/index.cfm?event=translationForm Browse to the site again], and you should see the default template "wrapping" the views. 
     84 
     85Congratulations, you've finished the Quickstart! 
    3086 
    3187----