freemarker-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Dekany <>
Subject Re: How to detect macro duplicates ?
Date Wed, 20 Jan 2016 18:16:48 GMT
The problem with detecting that is that macros aren't really
statically declared. Macros are created as the template runs the
#macro directive. It's quite analogous to #assign in that regard, and
of course you can assign to the same variable twice. However, unlike
with #assign, there's trick, which let's you call a macro that is
defined later. FreeMarker simply pre-assigns one of the definitions to
a variable, which will be simply overwritten by the later #macro

I'm not saying I'm big fan of the mechanism though. In FreeMarker 3, I
think it would be good to make things more static, such as #macro
would be completely parse-time. (If someone wants to call a macro
"dynamically", that should be possible, but an some different way.)
Among others because of tooling support. Many users want to analyze
templates, but the more dynamic the language, the less reliable the
results are.

Wednesday, January 20, 2016, 2:26:24 PM, Albert Kam wrote:

> Hi guys !
> My need is just to detect unintended macro name duplicates resulting from
> multiple template merges.
> I tried :
> <@test />
> <#macro test>
> Testing 1
> </#macro>
> <#macro test>
> Testing 2
> </#macro>
> And it prints out Test 2.
> What i expect is to throw exception upon finding dupes, or maybe in the
> template itself i can check the amount of macro variables ?

 Daniel Dekany

View raw message