Quantcast

How to use nested directives?

Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to use nested directives?

Stefan Undorf
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 -->
    <#if outFile?index_of(${m.item.link}) != -1>  <!-- syntax error -->

Complete example:

    <#assign menus = [
        {"item": {"name": "Motive", "link": "motive.html"}},
        {"item": {"name": "Action", "link": "action.html"}},
    ]>
    <#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?

Thanks,
Stefan

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
fmpp-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/fmpp-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use nested directives?

Daniel Dekany
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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
fmpp-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/fmpp-open
Loading...