Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Hello,
I am developing a website with couch cms.
It is some kind of buyers guide.
My client wants a page in which a list of categories will be displayed.
When you click on a category, it will link you to another page that a list of subcategories of the previous category, will be displayed. So when you click on a subcategory it will open a third page in which a list of blog posts will be displayed. And he wants everything, to be created dynamically by him.
Can I do it with Couch? My head will exlode...
Thanks a lot!!
Hi Cornelius :)

What you described is a fairly common scenario and can be easily handled in Couch.

I'll spell out a detailed solution below but it assumes that you have at least a passing familiarity with the concept of 'views' in Couch (i.e. home_view, folder_view, page_view). If the terms sound unfamiliar to you, I suggest you please take a look at the following page of our docs first -
http://docs.couchcms.com/concepts/views.html

That done, please take a look at the following thread where a use-case very similar to yours was discussed -
viewtopic.php?p=20975#p20975

The solution for your use-case is very similar to what is discussed in the aforementioned thread. Following is the working code for you to tinker with (I've commented it liberally so please do read the comments to know what is going on. We are assuming the template is 'photography.php') -
Code: Select all
<!-- home-view e.g. http://www.yoursite.com/photography/ -->
<cms:if k_is_home>

    <!-- show only the top-level folders (e.g. models & architecture)-->
    <cms:folders orderby='weight' order='asc' depth='1' >
   
        <!-- clicking the link below will lead to the folder-view -->
        <a href="<cms:show k_folder_link />"><h2><cms:show k_folder_title /></h2></a>
        <cms:show k_folder_desc />
       
        <hr />
       
    </cms:folders>

</cms:if>

<!-- folder-view e.g. http://www.yoursite.com/photography/models/ -->
<cms:if k_is_folder>

    <!--
        this is a folder-view so we are inside a folder (e.g. 'models') at this point.
        Show the immediate child folders of this folder
    -->
    <cms:folders childof=k_folder_name orderby='weight' order='asc' depth='1' >
   
        <!-- we are now within the child folders e.g. 'chocolate' or 'candy' -->
        <h2><cms:show k_folder_title /></h2>
        <cms:show k_folder_desc />
       
        <hr />
       
    </cms:folders>
   
    <!-- also show the cloned pages immediately within this folder -->
    <cms:pages folder=k_folder_name  include_subfolders='0'>
        <a href="<cms:show k_page_link />"><cms:show k_page_title /></a>
        .. all editable regions of the page available e.g. images or text ..
    </cms:pages>

</cms:if>

<!-- page-view e.g. http://www.yoursite.com/photography/models/some-page.html -->
<cms:if k_is_page>
    <h1><cms:show k_page_title /></h1>
    .. all editable regions of the page available e.g. images or text ..
</cms:if>

Assuming that the folder structure is as follows -
Code: Select all
models
   |__chocolate
   |__candy
architecture
   |_classical
   |_modern

The home_view will show
Code: Select all
models
architecture

Clicking 'models' (e.g.) will lead to the folder_view of 'models' where it lists its immediate child-folders and also pages immediately within 'models' (if any. In your case I think there will be none in top-level folders). So it will show -
Code: Select all
chocolate
candy

Clicking 'chocolate' will again lead to the folder_view but this time of 'chocolate' folder. So the same code will execute and try to show any child folders of 'chocolate' and any pages immediately within it. (in your case, I think this second level folder will only have pages and no folders so only the pages will be displayed).

Clicking on any page will lead to the 'page_view' where you can show the full details of the page.

Hope this helps.
THANX A LOT sir!!That did the job amazingly :D :D :D
I'm glad I could help :)
4 posts Page 1 of 1