Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I'm trying to set a li class to active if the folder name is equal to the current folder that we're in

Code: Select all
<cms:folders masterpage='products.php'>
                              <li class="<cms:if k_folder_name='<cms:show k_folder_name />'>active</cms:if>"><a href="<cms:show k_folder_link />" class="links">
                                 <cms:show k_folder_title />
                                 </a></li>
                           </cms:folders>
Assuming you are in a folder-view, a variable named 'k_folder_name' gets available that shows the folder being visited.

However, the cms:folders tag also sets its own variable named 'k_folder_name' (within its block) and so that 'shadows' the variable of the same name outside it.

To use the outside variable inside the tag block, we'll have to save its value in another variable like this -
Code: Select all
<cms:set my_current_folder=k_folder_name scope='global' />

<cms:folders masterpage='products.php'>
    <li class="<cms:if k_folder_name=my_current_folder>active</cms:if>"><a href="<cms:show k_folder_link />" class="links">
        <cms:show k_folder_title />
    </a></li>
</cms:folders>

Hope it helps.
KK wrote: Assuming you are in a folder-view, a variable named 'k_folder_name' gets available that shows the folder being visited.

However, the cms:folders tag also sets its own variable named 'k_folder_name' (within its block) and so that 'shadows' the variable of the same name outside it.

To use the outside variable inside the tag block, we'll have to save its value in another variable like this -
Code: Select all
<cms:set my_current_folder=k_folder_name scope='global' />

<cms:folders masterpage='products.php'>
    <li class="<cms:if k_folder_name=my_current_folder>active</cms:if>"><a href="<cms:show k_folder_link />" class="links">
        <cms:show k_folder_title />
    </a></li>
</cms:folders>

Hope it helps.

Didn't know that, thanks a lot it worked flawlessly!
3 posts Page 1 of 1