Re: [FMPP] How to use nested directives?
Brought to you by:
ddekany
From: Daniel D. <dd...@fr...> - 2012-05-22 21:27:42
|
Tuesday, May 22, 2012, 4:50:17 PM, Stefan Undorf wrote: > Hi fmpplers, > > I try to generate my menus dynamically and to activate the current menu item. So I use one directive > inside another but I do not know how to do it right. The following is taken from the example below: > > <#if outFile?index_of(m.item.link) != -1> <!-- m.item.link is undefined --> This is correct so far, although <#if outFile?cotains(m.item.link)> would be nicer. > <#if outFile?index_of(${m.item.link}) != -1> <!-- syntax error --> (It is an error since ${Expression} only makes sense put directly into static text or into a string literal. Elsewhere you can you just use Expression as is.) > Complete example: > > <#assign menus = [ > {"item": {"name": "Motive", "link": "motive.html"}}, > {"item": {"name": "Action", "link": "action.html"}}, (I assume there will be something else next to the "item" key in that map, or else that whole map could be eliminated, of course.) > ]> > <#if currentLanguage == "es"> > <#assign menus = [ > {"item": {"name": "Motivos", "link": "es/motive.html"}}, > {"item": {"name": "Acción", "link": "es/action.html"}}, > ]> > </#if> > <ul class="nav"> > <#list menus as m> > <li <#if outFile?index_of(m.item.link) != -1>class="active"</#if>> > <a href="${m.item.link}">${m.item.name}</a> > </li> > </#list> > </ul> > > How can I access the variable m.item.link in the #if? Just like you did. Furthermore your above example works for me. So, some of the items has no "link" in it or it's null. That's what the error message means. > Thanks, > Stefan -- Best regards, Daniel Dekany |