Forum for discussing general topics related to Couch.
10 posts Page 1 of 1
I have developed a news.php page and added 2 no. news folders.
I am displaying these news folders in a sidebar menu using the code below.

<div class="widget-container widget_categories">
<h3 class="widget-title">News Categories</h3>
<ul>
<cms:folders masterpage='news.php' orderby='title' >
<li class=""><a href="<cms:show k_folder_link />">
<span> <cms:show k_folder_title /></span></a></li>
</cms:folders>
</ul>
</div>

I want to put an active class on the folder which is currently selected. Is this possible??
Hi and welcome :)

Please try the following:
Code: Select all
<cms:set current_folder_name = k_folder_name />
<ul>
<cms:folders masterpage='news.php' orderby='title' >
    <li class="<cms:if current_folder_name=k_folder_name>active</cms:if>"><a href="<cms:show k_folder_link />">
    <span> <cms:show k_folder_title /></span></a></li>
</cms:folders>
</ul>

To explain the code: The 'folder-view' sets a variable named 'k_folder_name' that contains the name of the current folder. We save this in another variable named 'current_folder_name' and then compare it with the names of the folders as they are iterated using cms:folders tag (incidentally, the name of the variable set by cms:folders tag is also 'k_folder_name' which explains why we had to save the first one in another variable).

Hope this helps.
Yes worked a treat thanks.

Would this structure work in a similar way when displaying News Archives?
Would this structure work in a similar way when displaying News Archives?

Yes, certainly. The variable to use then would be 'k_archive_date' (assuming you use cms:archives tag to create the listing).

You might find the following links from our documentation useful:
http://www.couchcms.com/docs/concepts/v ... views.html
http://www.couchcms.com/docs/tags-refer ... hives.html

Hope this helps. Thanks.
currently using the code below, displaying fine but not recognizing the current item

<cms:set current_archive_date = k_archive_date />
<ul>
<cms:archives masterpage='news.php'>
<li<cms:if current_archive_date=k_archive_date> class="current-menu-item"</cms:if>> <a href="<cms:show k_archive_link />">
<span><cms:date k_archive_date format='F Y' /></span></a></li>
</cms:archives>
</ul>
OK, I checked and as it happens, the 'k_archive_date' set in archive-view is of format '2013-02-01 00:00:00' while that set by cms:archives tag is simply '2013-02-01'.

A slight modification to your original code (to factor in the ' 00:00:00' while comparing) makes it work as expected.
Following is the working code:
Code: Select all
<cms:set current_archive_date = k_archive_date />
<ul>
<cms:archives masterpage='news.php'>
<li<cms:if current_archive_date="<cms:concat k_archive_date ' 00:00:00' />" > class="current-menu-item"</cms:if>> <a href="<cms:show k_archive_link />">
<span><cms:date k_archive_date format='F Y' /></span></a></li>
</cms:archives>
</ul>

Hope this helps. Thanks.
yes the above code works no problem!!

Thanks for the solution.
Hey KK & friends,
My issue is with getting the current / active link class on a navigation menu for individual blog posts.
I'm using this solution for a navigation menu created from dynamic folders like this:

Code: Select all
 <ul>
  <cms:set current_folder_name = k_folder_name />
     <cms:folders masterpage='articles.php' orderby='weight'>
       <li>
         <a href="<cms:show k_folder_link />" class="nav-link <cms:if current_folder_name=k_folder_name>active</cms:if>"><cms:show k_folder_title /></a>
       </li>
     </cms:folders>
</ul>


However, when I click on a blog post link, the active/current class doesn't show up on the menu. It shows up, however, on the blog list view. What exactly am I missing? Should I be using the k_page_foldername variable somehow?
Hi,

I think the following should help -
Code: Select all
<cms:if k_is_page >
    <cms:set current_folder_name = k_page_foldername />
<cms:else />
    <cms:set current_folder_name = k_folder_name />
</cms:if>

Please let me know if it does.
@KK, yes, it works perfectly. Thank you so much!!! :)
10 posts Page 1 of 1

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 2 guests

cron