Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Is there a way to check the current template and then output a class="current" on archive and category links (instead of regular menu items)?

I tried:

Code: Select all
<cms:folders masterpage='index.php'>
    <li>
        <a href="<cms:show k_folder_link />" <cms:if k_template_name=='<cms:show k_folder_link />'>class="current"</cms:if>><cms:show k_folder_title /></a>
    </li>
</cms:folders>
Hi,

I am not sure I understand the problem completely.
By 'current template', I take you mean the template of the page being visited (let us suppose it is 'blog.php').
Further, if this page contains the 'cms:archives' or 'cms:folders' you mentioned (e.g. as follows ) -
Code: Select all
<cms:folders masterpage='index.php'>
..
</cms:folders>

<cms:archives masterpage='blog.php'>
..
</cms:archives>

- then, in the code above, do you wish to check if the 'masterpage' of the two tags is the same as the current template (in our example, this would be true for cms:archives)?

Or is it something else that you have in mind.
Please clarify. Thanks.
Thanks for getting back KK!

What I have in mind is I have a section called 'Archives' in my sidebar. With a list that contains August 2016, October 2016, November 2016, and so on.

Clicking on August 2016 would bring me to a page listing all posts from August 2016.

When on that page I would like for the link 'August 2016' in the section 'Archives' in the sidebar to have a current state, e.g. underlined or a different color.

Is this possible?

What I came up with myself didn't work.

Code: Select all
<ul>
   <cms:archives masterpage='index.php'>
      <li><a href="<cms:show k_archive_link />" <cms:if k_template_name=='current_folder'>class="current"</cms:if>><cms:date k_archive_date format='F Y' /></a></li>
   </cms:archives>
</ul>
OK, thanks. I get it now.

I think the following code should do what you want -
Code: Select all
<ul>
   <cms:archives masterpage='index.php'>
      <li><a href="<cms:show k_archive_link />" <cms:if k_is_archive && k_page_link=k_archive_link>class="current"</cms:if>><cms:date k_archive_date format='F Y' /></a></li>
   </cms:archives>
</ul>

To explain it a bit, in the modified code we test if the current view is an 'archive-view' and if yes, whether the page-link (current URL) is equal to the link displayed by the <cms:archives> item.
<cms:if k_is_archive && k_page_link=k_archive_link>class="current"</cms:if>

Hope it helps.
4 posts Page 1 of 1
cron