How do I set the current page for a global navigation cfm in ColdFusion Model Glue 3?

181 Views Asked by At

I have a navigation.cfm page that I'm including in all of my pages by using a MG3 custom event type:

<event-type name="pageWithNav">
    <after>
        <views>
            <include name="navigation" template="templates/navigation.cfm"/>
            <include name="maintemplate" template="templates/main.cfm"/>
        </views>
    </after>
</event-type>

And I'm using it in an event handler like so:

<event-handler name="page.home" type="pageWithNav">
    <views>
        <include name="body" template="pages/home.cfm"/>
    </views>
</event-handler>

My question is, how do I set a variable so that the navigation.cfm page knows what the current page is? So far I've done the following in the page.home event handler:

<include name="body" template="pages/home.cfm">
    <value name="currentPage" value="home"/>
</include>

By setting the value like this, it becomes available to all views that come after it. Although this works, the semantics is wrong because it looks like the currentPage variable is used by the home.cfm template instead of navigation.cfm. What would be the correct way of doing this?

1

There are 1 best solutions below

0
On

I'm not sure what the best practice is but you could consider setting a value in the viewstate from within the primary view that can be picked up the after views.

eg in the view pages/home.cfm use <cfset viewState.setValue("currentPage","home") />

and then in view templates/navigation.cfm use <cfset viewState.getValue("currentPage","") />

to retrieve it again.

I haven't tried this in the context of after event types but I do use this to set a pagetitle variable that the template uses to set the html title attribute.