Re: discover macro name

Ioannis Cherouvim <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Hi

OK here are the details.

I use freemarker to render html in my Java web applications. Usually I 
will have macros to render some html snippets such as search form, 
search result, login form etc because I reuse them in many projects and 
they feature the exact same html. The graphic designers (the people who 
initially do the static html layout) want to be able to see where these 
snippets start and end, in the final rendered product (when running on 
"debug" mode), in order to maintain/debug html rendering issues.

I've got around 30 of those macros.

So, instead of doing the following:
<#macro renderSearchForm>
  <!-- renderSearchForm starts -->
  <p>bla bla bla...</p>
  <!-- renderSearchForm ends -->
</#macro>

<#macro renderLoginForm>
  <!-- renderLoginForm starts -->
  <p>bla bla bla...</p>
  <!-- renderLoginForm ends -->
</#macro>


I'd like to be able to do something like:
<#macro renderSearchForm>
  <!-- ${currentMacroname} starts -->
  <p>bla bla bla...</p>
  <!-- ${currentMacroname} ends -->
</#macro>

So I don't have to maintain too much stuff, especially in case of macro 
name refactorings.

This will eventually lead me to a more generic macro such as:
<#macro renderSearchForm>
  <@commentWrap currentMacroname>
     <p>bla bla bla...</p>
  </@commentWrap>
</#macro>

Which will be a macro wrapping the nested html (using <#nested /> ) with 
the appropriate html comments.

thanks,
Ioannis


Daniel Dekany wrote:
> Sunday, March 23, 2008, 7:30:32 AM, Ioannis Cherouvim wrote:
>
>> Hello
>>
>> I'd like to know if it is possible to dynamically discover the currently
>> executing macro name. For example:
>> <#macro foo>
>>   ...
>> </#macro>
>>
>> What do I have to do in order for the macro above to output the word 
>> "foo"? That is the name of the macro.
>
> I don't know, but, out of curiosity, what is that needed for?
>
>> thanks,
>> Ioannis
>


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
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.