Shimju asks:
This is rather simple, and I think you already have most of the answer written out already. Typically folks do layouts in Model-Glue like so:In a model-glue app, suppose I have 3 templates files - templateA, templateB and templateC. All are set as private events in model-glue.xml. Now my requirement is I want to select a particular template dynamically based on Arguments.event.AddResult("templateA") which we set on contoller method for the event. Based on this, I want corresponding template should appear for that event. Can you please advice how we can accomplish this.
<event-handler name="page.index">
<broadcasts />
<results>
<result do="view.template" />
</results>
<views>
<include name="body" template="dspIndex.cfm" />
</views>
</event-handler>
<event-handler name="view.template">
<broadcasts />
<results />
<views>
<include name="template" template="dspTemplate.cfm" />
</views>
</event-handler>
The event, page.index, has one result. Because it is unnamed, and the only result, it will always run. So all calls to page.index always run view.template. As you have already suggested, you can simply add other results. So let's say you want to have a default template, and two alternates, slim and print. Your controller could decide to add those results based on some logic, like the existence of a print attribute:
<cfif arguments.event.valueExists("print")>
<cfset arguments.event.addResult("print")>
</cfif>
The modified XML could then look like so:
<event-handler name="page.index">
<broadcasts />
<results>
<result name="print" do="view.printtemplate" />
<result do="view.template" />
</results>
<views>
<include name="body" template="dspIndex.cfm" />
</views>
</event-handler>
<event-handler name="view.template">
<broadcasts />
<results />
<views>
<include name="template" template="dspTemplate.cfm" />
</views>
</event-handler>
<event-handler name="view.printtemplate">
<broadcasts />
<results />
<views>
<include name="template" template="dspPrintTemplate.cfm" />
</views>
</event-handler>
This simply reads as - if no result was fired, use the view.template template, but if the print result was used, fire off view.printtemplate.
Pretty simple, but I wonder if this could be done easier? (And yes, I'm being sly. Look later today for another example using Model-Glue 3, or as I call it, the Super-Fantastic Uber Framework.)
Archived Comments
Hey Rey, this is such an easy stuff and Iam surprised it didnt went over my head:)
It could most definitely be done easier... where is the graphical IDE for this stuff? Compare editing databases with graphical UI to doing everything in code. (Especially relationships.) I will enjoy seeing what Joe or someone can do with AIR or another tool to come up to speed on this way of making it easier.
John, have you looked at the Frameworks Explorer that ships w/ CFEclipse?
Not with Model Glue. Someone should do a YouTube or hook up with Charlie on that if it can do the job. It would be a big boost for the MG community. :)
Later we may extend D2O to support some of those types of features... but that will be after 1.0 for sure. I think it is the way all of our IDE tools should move when able. We need some more advanced tools that go beyond text editing. Of course keep the text stuff friendly. This is a great post on that. My long term concern is always not what can be done friendly... but rather what won't be. (standard programmer paranoia.)
Sorry John - are you asking for an IDE to help work with frameworks, or videos to help you learn how to use it? Seems like two different requests.
D20?
I bet it's something about the format attribute in MG 3 :)
I find it makes things clearer in the xml as well if you omit the EMPTY broadcasts,views or results. I find that it's easier and quicker to read or skip thru
Actually I was going to demo eventtypes, but I ran into a few bugs. One is already fixed, one I'm waiting to hear back from Joe. The fun of working with Alpha software. ;)