freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <>
Subject [jira] [Commented] (FREEMARKER-25) Multiple nest targets
Date Mon, 30 May 2016 17:33:12 GMT


Daniel Dekany commented on FREEMARKER-25:

This is one of the most wanted missing features (well, variations of this), but was never
implemented. Something that you can do to work this around is introducing a {{TemplateDirectiveModel}}
that captures its output and then puts it into a custom {{Map}} attribute in the {{Environment}}
with a given key (like "{{HEADER"}} in your case). Then, with another {{TemplateDirectoveModel}},
to which you specify the same key ({{"HEADER"}}) you print the captured content to the output.
If you know FreeMarker enough, I think the end result can look very close to a core feature.
Like you can capture with {{<@def.header>...</@>}}, then print with {{<@printDef.header
/>}}. And, the enclosing macro ({{MY_TABLE}}) needs to set up the scope which created a
clean {{Map}} in the {{Environment}}, like {{<@collectDefs>...<#nested>...<@printDef.header
...>...</@collectDefs>}}. Something like that. But of course it should be a core
feature. I think I will try to prototype this using custom directives when I find the time.

> Multiple nest targets
> ---------------------
>                 Key: FREEMARKER-25
>                 URL:
>             Project: Apache Freemarker
>          Issue Type: Wish
>          Components: engine
>    Affects Versions: 2.3.24
>            Reporter: Charles Goodwin
> We spend a lot of time getting around the inability to have multiple nest targets in
our freemarker usage.
> For example, defining a table with a custom column header/cells.
> The desired feature would work something like:
> {noformat}
> <#macro MY_TABLE>
>     <table>
>         <head>
>             <column A/>
>             <column B/>
>             <#nested HEADER>
>         </head>
>         <body>
>             <rowtemplate>
>                 <celldef A/>
>                 <celldef B/>
>                 <#nested>
>             </rowtemplate>
>          </body>
>      </table>
> </#macro>
> {noformat}
> With the end usage being:
> {noformat}
>     <@:HEADER>
>         <column C/>
>     </@:HEADER>
>     <celldef C/>
> </@MY_TABLE>
> {noformat}

This message was sent by Atlassian JIRA

View raw message