2014-03-02 2 views
0

일부 FreeMarker 매크로에는 다른 매크로를 허용하는 매개 변수가 있습니다. 이렇게하면 기이 한 경우에 페이지의 표준 부분을 변경할 수 있습니다. 아래 예제에서 article 매크로는 기본적으로 defaultHeader를 사용합니다. 때로는 alternativeHeader 매크로를 헤더 매개 변수로 전달하여 alternativeHeader를 사용합니다. 이것은 잘 작동합니다.FreeMarker에서 매개 변수로 매크로를 자체 매개 변수로 전달

가끔 alternativeHeader 매크로를 전달하지만 텍스트 매개 변수를 변경하려고합니다. 이 작업을 수행하는 방법을 알고있는 유일한 방법은 다른 '호출자'매크로를 만든 다음이 매크로를 사용하는 것입니다. 그러나 이것은 내가이 '호출자'매크로를 많은 페이지에 추가해야한다는 것을 의미하며 단지 더러워 보입니다. alternativeHeader 매크로를 매개 변수를 설정하는 동안 직접 전달하는 또 다른 방법이 있습니까?

<html> 
    <head><title>test</title></head> 
    <body> 
     <@article body="First example"/> 
     <@article body="Second example" header=alternativeHeader/> 
     <@article body="Third example" header=alternativeHeaderCaller/> 
    </body> 
</html> 

<#-- 
    These three macros would usually be contained in a library. 
--> 
<#macro article body header=defaultHeader> 
    <div> 
     <@header/> 
     <br> 
     ${body} 
    </div> 
</#macro> 
<#macro defaultHeader> 
    This is a default header 
</#macro> 
<#macro alternativeHeader text="This is an alternative header"> 
    ${text} 
</#macro> 

<#-- 
    I want to avoid having to add and use this macro. 
--> 
<#macro alternativeHeaderCaller> 
    <@alternativeHeader text="I have changed this header"/> 
</#macro> 

출력

<html> 
    <head><title>test</title></head> 
    <body> 
    <div> 
    This is a default header 
     <br> 
     First example 
    </div> 
    <div> 
    This is an alternative header 
     <br> 
     Second example 
    </div> 
    <div> 
    I have changed this header 
     <br> 
     Third example 
    </div> 
    </body> 
</html> 

내가 더 "무두질"기능은 없습니다 ... 난 당신이 더 나은 아무것도 할 수 없어 유감이

<@article body="Third example" header=alternativeHeaderCaller(text="My other text")/> 

답변

1

뭔가를 찾고 있어요 FTL로