Re: Data model traverse
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Wednesday, March 25, 2009, 9:50:38 PM, wkbutler wrote:
>
> Hi -
> I know this has been asked before, but I have not seen an answer that seems
> to work for me. I am looking to discover the contents of the data model
> during template processing time, just for the purpose of setting up a
> debugging FTL template.
>
> Is there a constant keyword for the root of the model?
>
> I have seen .data_model used but for me that was an Environment object (and
You have overlooked something there; .data_model is the root of the
data-model itself. It's not an Environment object (of course, unless
someone uses the Environment object as the data-model parameter in
Template.process... but that's at best unusual.)
> accessing .data_model.dataModel as I thought should have been
> possible, according to the freemarker.core.Environment API, result
> in an 'undefined' error).
>
> This thread asks the same question
> http://www.nabble.com/traverse-the-data-tree-td6874906.html#a6874906
>
> and Attila mentions it's possible but unfortunately did not
> elaborate. Using <#recurse> is apparently valid but for me resulted
> in an error also.
#recurse only works for FTL node values, like wrapped XML-s. I doesn't
work for plain hashes and like. You should use ?keys on them, like:
<p>The variables in the data-model are:
<ul>
<#list .data_model?keys as key>
<li>${key?html}
</#list>
</ul>
> Thanks for any advice!
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------