Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi,

I'm building a site for the first time using Couch and I love it! The tutorials have been very useful but I'm struggling to implement something.

I have a collection of nested pages all with a menu on the side of the page, I'd like that menu to list any child pages (which I can do easily with the menu tag) but when the user gets to the bottom of the tree and there aren't any more child pages to display I'd like the menu to display all pages at the same level of the page they are currently on.

For example looking at the attached image:

Users on the 'Curriculum' page will see the menu populated with:

    English
    Mathematics
    Science

Users on the 'English' page will see the menu populated with:

    Key Stage 3
    GCSE English

Users on either the 'Key Stage 3' or 'GCSE English' pages will see the menu populated with:

    Key Stage 3
    GCSE English

I'm sure I've missed something obvious but can't find anything in the tutorial or forums.

Many thanks!

Attachments

Or is there a way of achieving the above functionality using folders?

I'd even be happy just having a back button to return to there parent, I found a method here: viewtopic.php?f=4&t=9644&view=next

But on the topmost parent I end up with a link for each child page (6 based on the structure above).
Hi @hankscorpio,

Apologies for the delay in this reply.

Answering your query - let us stick with your original solution using nested-pages.
Try the following out -
Code: Select all
<cms:if k_is_page>
   
    <cms:set my_has_children='0' 'global' />
   
    <!-- show children of the current page -->
    <ul>
    <cms:nested_pages childof=k_page_name depth='1'>
        <li><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_title /></a></li>
       
        <cms:set my_has_children='1' 'global' />
    </cms:nested_pages>
    </ul>
   
    <!-- if no children, show those of its parents -->
    <cms:if my_has_children='0' >
        <ul>
        <cms:nested_pages childof='@current-1' depth='1'>
            <li><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_title /></a></li>
        </cms:nested_pages>
        </ul>
    </cms:if>
   
</cms:if>

The code above does exactly what you specified. You can tweak it to suit your design.

Explaining the code, the cms:menu and cms:nested_pages tags support dynamic values as their 'childof' and 'root' parameter - please see http://docs.couchcms.com/tags-reference ... namic-menu

Using that we can easily target the parent of any page -
<cms:nested_pages childof='@current-1' depth='1'>

Hope it helps. Do let us know.
That's exactly what I was looking for! Thanks so much KK!

I had found the information in your link but was missing the cms:set my_has_children='0' tag.

So happy right now. :D
4 posts Page 1 of 1