[stringtemplate-interest] best way to expose xml in template

Nate misc at n4te.com
Wed Dec 6 13:09:03 PST 2006


Terence Parr wrote:
> On Dec 5, 2006, at 5:24 PM, Nate wrote:
>> Thanks for the reply.
>>
>> It would be great if there were an interface that could be implemented
>> that had simply #get(String).
>>     
>
>   That is probably too flexible, leading a bigger hole I want.   
> Allowing the map interface took a lot of convincing from other people  
> before I did it. ;)
>   
Maybe true, but the hole is there either way.

>> Also Collection could be supported... $if (someSet.moo)$ would be
>> equivalent to the Java: if (someSet.contains("moo"))
>>     
>
> That is too much like logic I think.
>   
While this message has the subject "best way to expose xml in a 
template", the actual problem I encountered that prompted support for 
Collection#contains is this... I have a user object with a Set<String> 
of "capabilities". I would like to check in my templates if the user has 
a given capability. Eg, the template should show an "admin tools" link 
if the user has the capability "can view admin tools". I could manually 
add the capabilities that the template needs to know about as 
attributes, but if a different set of templates is used to display the 
page then they may require knowledge of different capabilities. Eg, the 
"admin tools" link may be in a different template. The easiest solution 
I think is to add an attribute for every template called "capabilities" 
that contains the Set, then use...
$if(capabilities.("can view admin tools"))$<a href=...>admin 
tools</a>$endif$

-Nate



More information about the stringtemplate-interest mailing list