Re: Print a random node?
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, February 22, 2008, 3:05:17 PM, biffjo wrote: > I have an XML file with 3 items. I am looping through this file from within > an .ftl template. Is it possible to randomly print only one of the items? If > so, what is the best approach? Choosing the item is the task of the MVC Controller, not of the View, so you should put a random integer between 1 and 3 into the data-model before processing the template. If this MVC-ish approach doesn't fit your case, then write a TemplateMethodModelEx implementation that returns a random number, and the put that into the data-model (possibly as Configuration level "shared variable"), or into an "FTL library". > Thanks in advance, > B -- Best regards, Daniel Dekany ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/