Re: can a macro have 2 nested areas?

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Monday, May 28, 2012, 2:13:34 PM, Daniel López wrote:

> Wouldn't this also work?
> <#macro head>
> ...
> </#macro>
> <@page>
>
> </@page>
>
> and then inside the page macro definition, use <@head/> ?

That's not a good solution, because in the scope of the called macro
there can be another variable called "head" (like a macro parameter or
other local) which hides the global one. Also, the called macro might
uses another name-space than the caller, in which case head wouldn't
be visible.

> I remember having used something like that. The only downside being that
> you have to remember to define all the macros you use, even if empty, in
> all the places you use the general macro.
>
> S!
> D.
>
> El 28/05/2012 13:07, Daniel Dekany escribió:
>> A macro call can have only one piece of nested content. You had to
>> pass in the JavaScript as a parameter to the macro. Unfortunately,
>> there's no syntactical sugar for passing in anonymous macros as
>> parameters, so what you have to do is:
>>
>>    <#macro myJSGenerator>
>>      ...
>>    </#macro>
>>    <@page javascript=myJSGenerator>
>>      ...
>>    </@page>
>>
>> Then inside the page macro you had to do something like:
>>
>>    <head>
>>       <#if javascript?is_directive><@javascript/><#else>${javascript}</#if>
>>    </head>
>>
>> so now the javascript parameter can be a string or a macro that prints
>> javascript.
>>
>>
>> Monday, May 28, 2012, 5:15:49 AM, S Ahmed wrote:
>>
>>> My page template macro looks like:
>>>
>>> <#macro page ...>
>>>
>>> <html>
>>> ..
>>> <head>
>>> JAVASCRIPT HERE
>>> </head>
>>> <body>
>>> ...
>>> <#nested>
>>> ..
>>> </body>
>>> </html>
>>>
>>> </#macro>
>>>
>>>
>>> But I want to be able to do is, from within another ftl page that
>>> uses the above macro, I want to inject javascript in the section in the head of the html, so like:
>>>
>>>
>>> <#macro page ...>
>>>
>>> <html>
>>> ..
>>> <head>
>>> JAVASCRIPT HERE
>>> <#javascript>
>>> </head>
>>> <body>
>>> ...
>>> <#nested>
>>> ..
>>> </body>
>>> </html>
>>>
>>> </#macro>
>>>
>>>
>>> Is that possible?
>>>
>>
>
>

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
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.