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

Working with CouchCMS is a breese and I'm finding out new way how to work with it.
I've got a question I can't find in the documentation or on the forum.

With cms:pages I'm able to create pages, add them to a folders. Like this I can filter pages based on their folder:
Code: Select all
               <cms:pages masterpage='chapters.php' folder=k_folder_name order='asc' >
                  <div class="content">
                     <h1><cms:show k_page_title /></h1>
                     <cms:show content />
                  </div>
               </cms:pages>


One drawback with this way of making pages is I can't show the list in the admin panel 'asc' based on the folder names. Or can this be done?

Because of this issue I started using nested pages because they make it possible to create pages with subpages and them around in the admin panel. The problem I'm having with nested pages is that I can't find a way to display a list of pages based on their parent page, like pages can only belong to a folder.

The code for display nested pages looks like this only I can't find a way to display them so they behave like pages in folders:

Code: Select all
               <cms:nested_pages masterpage='chapters-nested.php' >
                  <div class="content">
                     <h1><cms:show k_nestedpage_title /></h1>
                     <cms:show content />
                  </div>
               </cms:nested_pages>


What's needed to change this code so every chapter in the frontend displays a list of pages belonging to a parent page?
Hi,
One drawback with this way of making pages is I can't show the list in the admin panel 'asc' based on the folder names. Or can this be done?
If you could upgrade to Couch v1.4RC, it has an option of creating your own admin-screens (using plain HTML and regular Couch tags). Please see 'Custom admin screens' section at http://www.couchcms.com/docs/concepts/d ... forms.html for details.

If, however, you wish to use nested-pages to simulate the 'pages - folders' structure, even that is a perfectly valid approach.

Let us suppose the following is your nested-pages structure -
Code: Select all
Chapter 1
    Page 1
    Page 2
    Page 3
Chapter 2
    Page 3
    Page 4
    Page 5

where 'Chapter 1' and 'Chapter 2' are top-level pages simulating the folders.

The following code will list only the top-level pages (chapters) in the home-view-
Code: Select all
<cms:if k_is_home>
    <cms:nested_pages masterpage='chapters-nested.php'  include_custom_fields='1' depth='1' >
        <h1><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_name /></a></h1>
    </cms:nested_pages>
</cms:if>

The 'depth' parameter used in the code above constrains the listing to only the top-level pages.

Now, when one of the link above is clicked it will lead us to the page-view where we want to list only the sub-pages of the current page. Following code will do it -
Code: Select all
<cms:if k_is_page>
    <cms:nested_pages masterpage='chapters-nested.php' include_custom_fields='1' childof=k_page_name >
        <h1><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_name /></a></h1>
    </cms:nested_pages>
</cms:if>

The 'childof' parameter sees to it that only the children of the current page are listed.

If, however, now one clicks on the links to the child pages, the same code as above gets executed - remember 'Chapter 1' and 'Page 1' are both pages.

We need to differentiate between the top-level pages (simulating the folders) and the child pages.
To do this we can modify the code to now become -
Code: Select all
<cms:if k_is_page>
    <cms:if k_nested_parent_id='-1'>
   
        <!-- This is a top-level page. So list sub-pages -->
        <cms:nested_pages masterpage='chapters-nested.php' include_custom_fields='1' childof=k_page_name >
            <h1><a href="<cms:show k_nestedpage_link />"><cms:show k_nestedpage_name /></a></h1>
        </cms:nested_pages>
   
    <cms:else />
   
        <!-- This is a sub-page. Show its content the regular way -->
        <div class="content">
            <h1><cms:show k_page_title /></h1>
            <cms:show content />
        </div>       
       
    </cms:if>
</cms:if>

The top-level pages don't have a parent page so their 'k_nested_parent_id' is set to '-1'. We make use of this property to differentiate between the two kinds of pages.

Hope this helps.
Thank you very much KK for the brief explanation of my questions.
Because the folder solution can contain >1000 pages easily this one has my favour.
I'll have a look at both solutions and see which one will suit my needs the best.
3 posts Page 1 of 1