Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
Hello,

I'm trying to implement a sidebar / sub nav on my pages, the site is only 2 deep currently and what happens with my code below is on the parent page it's pulling in the parent site pages, what I am trying to achieve is the display of the child pages of the active page, then when in a child page it should maintain the other child pages of that parent. Does that make sense?

Code: Select all
<div class="visible-desktop visible-tablet">
   <ul class="nav nav-pills nav-stacked">
   
   <cms:nested_pages masterpage='pages.php' root='@current-1' depth='0'>
      <li<cms:if k_is_active && k_level !='0'> class="active"</cms:if>><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_title /></a></li>
   </cms:nested_pages>

   </ul>
</div>
   


If I use childof @current instead I can achieve the direed sub nav at parent level, but clicking into a child shows no menu because there are no children for that page.

I was wondering if there is a way to conditionally use childof and root, something like:

<cms:if nested_page_depth ='0'>
<cms:nested_pages masterpage='pages.php' childof='@current' depth='0'>
<cms:else>
<cms:nested_pages masterpage='pages.php' root='@current-1' depth='0'>
</cms:if>



Perhaps there is a simpler / better approach I have overlooked?
Hi Patrick,

Could you please 'illustrate' the problem by giving a sample hierarchy of pages and how things are working right now (i.e. which pages get shown) and how they should really work?
Will make it a lot easier to grasp the problem.
Thanks.
If I understood the problem correctly, assuming following is a sample hierarchy of nested-pages,
Code: Select all
parent-0
   child-0
   child-1
   child-2

Upon visiting 'parent-0', you wish to show
Code: Select all
child-0
child-1
child-2

while upon visiting a child page (e.g. child-1), you wish to show
Code: Select all
parent-0
   child-0
   child-1 (active)
   child-2

Following could be a solution:
Code: Select all
    <cms:nested_pages masterpage='pages.php'>
        <cms:if k_nestedpage_id = k_page_id >
            <cms:set nested_page_depth = k_level 'global' />
        </cms:if>
    </cms:nested_pages>
   
    <ul class="nav nav-pills nav-stacked">
        <cms:nested_pages masterpage='pages.php'
           root="<cms:if nested_page_depth>@current-1</cms:if>"
           childof='@current' depth='0'>

            <li<cms:if k_is_active && k_level !='0'> class="active"</cms:if>><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_title /></a></li>

        </cms:nested_pages>
    </ul>

In the code above, we use an additional loop of cms:nested-pages to find which level the current page is at. If it is at level that is non-zero (i.e. a child) we conditionally set the 'root' to
@current-1 (as the docs state - when both 'root' and 'childof are set, the 'root' gets precedence).

Hope this helps.
Hi KK,

At the moment I have:

- Home
- About
-- History
-- Team
- Services
-- Service 1
-- Service 2
-- Service 3
-- Service 4
- News
- Contact Us

If I visit "Services" using
<cms:nested_pages masterpage='pages.php' childof='@current' depth='0'>


I get my correct subnav:

-- Service 1
-- Service 2
-- Service 3
-- Service 4

However, if I visit one of those sub pages, i.e. Services > Service 1, I get no side menu - however If I was to use:

Code: Select all
   <cms:nested_pages masterpage='pages.php' childof='@current-1' depth='0'>


with -1 on my child page it continues to display the other child of the parent service page - which is what I want, yet because it's -1 when you go back to "Services" to shows this in the sidebar (i.e. all parent pages)

- Home
- About
- Services
- News
- Contact Us


Hope that explains it a bit better
OK, a slight variation of my previous solution should do that
Code: Select all
    <cms:nested_pages masterpage='pages.php'>
        <cms:if k_nestedpage_id = k_page_id >
            <cms:set nested_page_depth = k_level 'global' />
        </cms:if>
    </cms:nested_pages>
   
    <ul class="nav nav-pills nav-stacked">
        <cms:nested_pages masterpage='pages.php'
            childof="@current<cms:if nested_page_depth>-1</cms:if>"
            depth='0'>
           
            <li<cms:if k_is_active> class="active"</cms:if>><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_title /></a></li>
       
        </cms:nested_pages>
    </ul> 

Here we only add the additional '-1' to @current if we are visiting a child.
Does this help?
@KK - thanks! that works perfectly for what I was trying to achieve.
6 posts Page 1 of 1
cron