Freemarker directive suggestion: #namespace

Denis Bredelet <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
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.

------------------------------------------------------------------------------
BlackBerry&reg; 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.