Re: Freemarker directive suggestion: #namespace
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Thursday, August 4, 2011, 8:57:23 AM, Denis Bredelet wrote:
> Hello
>
> I want to suggest a new Freemarker directive called #namespace. It
> is similar to #import, except the imported template is the directive body and it can produce output.
>
> The namespace name is optional. Declarations inside an anonymous namespace cannot be used outside.
>
> Together with macro parameters, I think that can solve the
> "multi-parts macro" problem (but it has other uses). For example:
>
>
> [#namespace page]
>
> [#-- Define local macros for default header and footer (can be changed later) --]
>
> [#macro default_header]
> [/#macro]
>
> [#macro default_footer]
> [/#macro]
>
> [#-- Macro to render the page --]
>
> [#macro render header=default_header footer=default_footer]
> [@header/]
> [#nested]
> [@footer/]
> [/#macro]
>
> [/#namespace]
>
>
> [#namespace]
>
> [#macro page_header]
> <div class="header">${company}</div>
> [/#macro]
>
> [#macro page_footer]
> <div class="footer">(C) ${copyright}</div>
> [/#macro]
>
> [#-- Output the page --]
>
> [@page.render page_header, page_footer]
> <div class="content">Test page render</div>
> [/@page.render]
>
> [/#namespace]
>
>
> What do you think?
>
> -- Denis.
I don't think that it would be a proper solution for the multiple
bodies problem. You have to pass in `head` and `footer` as parameter
at both places... quite inconvenient. Also it's kind of difficult to
grasp.
BTW this multiple bodies problem starts to be embarrassing for
FreeMarker, so something had to be done... But the problem is not that
I can't figure out a solution for that (by extending the macro
system), but that I have no time (or incentive) to implement it.
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1