Re: Call macro with new root

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
It's not possible to do as far as I see. Especially as it should be
lexically scoped (in most applications at least). The best you can do
is something like:

  <#macro Product>
    <#local c = latestProduct> <#-- c for context -->
    ${c.name} (${c.url})
  </#macro>

Then at least it's obvious what's going on...

-- 
Best regards,
 Daniel Dekany


Thursday, July 28, 2011, 9:24:14 PM, John Redford wrote:

> I want to be able to call a macro with a given node used as the effective "root"
> for the called macro.  For example, given the data model:
>
> (root)
>   |
>   +- user = "Big Joe"
>   |
>   +- latestProduct
>       |
>       +- url = "products/greenmouse.html"
>       |
>       +- name = "green mouse"
>
> I want to have these macros:
>
> <#macro Product>
>  ${name} (${url})
> </#macro>
>
> <#macro Describe>
>  ${user}'s latest product is <@Product=latestProduct/>.
> </#macro>
>
> Such that the result is:
>
> Big Joe's latest product is green mouse (products/greenmouse.html).
>
> I have looked into ways to achieve something like this using
> TemplateDirectiveModel to writing a directive that re-roots the environment, but
> that does not seem possible.
>
>
> ------------------------------------------------------------------------------
> Got Input?   Slashdot Needs You.
> Take our quick survey online.  Come on, we don't ask for help often.
> Plus, you'll get a chance to win $100 to spend on ThinkGeek.
> http://p.sf.net/sfu/slashdot-survey
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>


------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
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.