Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
hello! I'm sure this can be done with Couch - it's something a bit different to everything I've done previously and I can't quite get it to all function at the same time :( and can't find anything like this in the forums.

I have a cloneable template projects.php with dynamic folders. PROJECTS is a link in the main nav. What I want to achieve is:

1. PROJECTS page has sub-nav level 1 = filtering by folder.

2. PROJECTS page has sub-nav level 2 = list of all the pages within current folder.

3. A single PROJECT page details are shown on the PROJECTS page at any one time.

4. Click on main nav link PROJECTS and view the 1st page within the 1st folder displayed on the PROJECTS page with sub-navigation links to all the other pages within that 1st folder (and current page link = current page).

5. Thereafter, navigation can be by Folder or by page.

What I am hoping is that with pretty URLs switched on when clicking on PROJECTS from the main menu the URL will be http://www.website.com/project1/page1.html

Any guidance much appreciated! Thanks.
Hi Potato,

Not sure if I understood all the points completely but I'll try to provide a solution for whatever I could gather.

I think this is the kind of menu structure you are looking for (the 'Projects' portion is what we are interested in )
Code: Select all
<div id='menu'>
    <ul>
        <li><a href='#'>Home</a></li>
       
        <li><a href='#'>Projects</a>
            <ul>
                <li><a href='#'>Project 1</a>
                    <ul>
                        <li><a href='#'>Page 1 of Project 1</a></li>
                        <li><a href='#'>Page 2 of Project 1</a></li>
                    </ul>
                </li>
                <li><a href='#'>Project 2</a>
                    <ul>
                        <li><a href='#'>Page 1 of Project 2</a></li>
                        <li><a href='#'>Page 2 of Project 2</a></li>
                    </ul>
                </li>
            </ul>
        </li>
       
        <li><a href='#'>About</a></li>
        <li><a href='#'>Contact</a></li>
    </ul>
</div>

Assuming your folder structure is flat, this is how we can create a dynamic version of the above menu -
Code: Select all
<div id='menu'>
    <ul>
        <li><a href='#'>Home</a></li>
       
        <li><a href='<cms:link 'projects.php' />'>Projects</a>
            <ul>
            <cms:folders masterpage='projects.php' depth='1' orderby='weight'>
                <li><a href='<cms:show k_folder_link />'><cms:show k_folder_title /></a>
                    <cms:if k_folder_pagecount >
                    <ul>
                        <cms:pages masterpage='projects.php' folder=k_folder_name >
                            <li><a href='<cms:show k_page_link />'><cms:show k_page_title /></a></li>
                        </cms:pages>   
                    </ul>
                    </cms:if>
                </li>
             </cms:folders>   
            </ul>
        </li>
       
        <li><a href='#'>About</a></li>
        <li><a href='#'>Contact</a></li>
    </ul>
</div>

You can set the weights of the folders to set their display order.

So that, I think, should handle your points 1 and 2 - we are displaying folders on level one with their respective pages on level 2.

I couldn't get point 3, I am afraid -
A single PROJECT page details are shown on the PROJECTS page at any one time.
Could you please explain that a bit more? Would be better if you can give some example or pseudo-code.

As for point no. 4 -
Click on main nav link PROJECTS and view the 1st page within the 1st folder displayed on the PROJECTS page with sub-navigation links to all the other pages within that 1st folder (and current page link = current page).
As you can see from the menu, clicking on 'Projects' will lead us to the 'home-view' of the template. I think you can easily embed a snippet in that view showing whatever you desire.
Let us know if you require help with that.

Hope this helps.
hi KK - sorry for not making it crystal clear ... here is a screen shot of the main nav, page and sub nav - hopefully this will be more obvious what I am after ...
projects-navigation.jpg
projects-navigation.jpg (34.75 KiB) Viewed 3130 times


... which is main navigation with a link 'RESEARCH PROJECTS' - which when clicked takes you to the first project in the first folder with sub navigation showing all the projects within this folder. Navigation to other folders is underneath the main navigation.

I had this code in the main navigation link:
Code: Select all
         <cms:set folder_count='0' />
            <cms:folders masterpage='research-projects.php' depth='1' orderby='weight' >   
         <cms:if folder_count=='0' >   
            <cms:set folder_name=k_folder_name 'global' />   
               <cms:incr folder_count '1' />
          </cms:if>
          </cms:folders>
          <cms:set current_template_name=k_template_name />
          <cms:pages masterpage='research-projects.php' limit='1' folder=folder_name include_subfolders='0'  >
             <li><a href="<cms:show k_page_folderlink />"<cms:if k_template_name==current_template_name> class="current"</cms:if>>Research Projects</a></li>
          </cms:pages>

But I wasn't able to tie it all together with the sub-navigation and showing the folder/page in the URL.

I currently have this code for the main navigation link:

Code: Select all
          <cms:set folder_count='0' /><cms:set page_count='1' />   
          <cms:if folder_count=='0' >   
         <cms:folders masterpage='research-projects.php' depth='1' orderby='weight'>
            <cms:set current_template_name=k_template_name />
                  <cms:pages masterpage='research-projects.php' limit='1' folder=k_folder_name >
                     <cms:if page_count=='1' ><li><a href='<cms:show k_page_link />' <cms:if k_template_name==current_template_name> class="current"</cms:if>>Research Projects</a></li>
                     </cms:if>
                     <cms:incr page_count '1' />
               </cms:pages>
            <cms:incr folder_count '1' />   
             </cms:folders>
          </cms:if>


I added the page_count because for some reason that I don't understand the limit='1' parameter in the cms:pages wasn't having any effect.

This may be closer to the correct answer - but I'm struggling! Either it is more complicated than my usual set ups or I'm having a bad day!
A picture is worth more than a thousand words indeed :)
Thanks. I get it now.

I see that you are trying to link the 'home-view' (and, although you have not made it explicit, the 'folder-view' also) to the first page of the appropriate folder.

While your solution is to explicitly figure out that page's link and output the link in the menus,
I would have approached this problem a little differently.

NOTE: I am assuming that the folder hierarchy is flat and that every page is within some folder.

Let us start with the page-view
Code: Select all
<cms:if k_is_page>
    <!-- Sub navigation by folders (level 1) -->
    <ul>
    <cms:folders depth='1' orderby='weight'>
        <li><a href="<cms:show k_folder_link />" <cms:if k_page_foldername=k_folder_name>class="current"</cms:if>><cms:show k_folder_title /></a></li>
    </cms:folders>
    </ul>
   
    <!-- contents of the page -->
    <h1><cms:show k_page_title /></h1>
    <p>page contents here</p>
   
    <!-- Sub navigation by pages (level 2)-->
    (Contents of '<cms:show k_page_foldertitle />' folder)
    <ul>
        <cms:set current_page=k_page_name />
        <cms:pages folder=k_page_foldername>
            <li><a href="<cms:show k_page_link />" <cms:if k_page_name=current_page>class="current"</cms:if>><cms:show k_page_title /></a></li>   
        </cms:pages>
    </ul>
</cms:if>

You'll see that visiting any page will properly display the two sub-menus we have
- folders with the current folder highlighted and
- pages within the current folder with the current page highlighted.

That done, let us now handle the home-view (i.e. when the main menu is clicked).
I'll make the link in the main menu point directly to the template itself (i.e. home-view)
Code: Select all
<li><a href='<cms:link 'research-projects.php' />' <cms:if k_template_name='research-projects.php'> class="current"</cms:if>>Research Projects</a></li>


Add the following code to the template -
Code: Select all
<cms:if k_is_home>
    <cms:folders depth='1' orderby='weight'>
        <cms:pages folder=k_folder_name>
            <cms:redirect k_page_link />
        </cms:pages>
    </cms:folders>
</cms:if>

The code is a standard loop through the folders and their pages. What we are doing is that as soon as the first page of the first folder is reached, we redirect to that page.
So, effectively, it is the page-view code we saw above that executes for the home-view.

We can handle the folder-view similarly -
Code: Select all
<cms:if k_is_folder>
    <cms:pages folder=k_folder_name >
        <cms:redirect k_page_link />
    </cms:pages>
</cms:if>

As you can see, it is always the page-view that gets displayed when clicking a folder or the template link (and, of course, clicking a page link too).

The complete code is
Code: Select all
<!-- top menu -->
<li><a href='<cms:link 'research-projects.php' />' <cms:if k_template_name='research-projects.php'> class="current"</cms:if>>Research Projects</a></li>

<!-- home view -->
<cms:if k_is_home>
    <cms:folders depth='1' orderby='weight'>
        <cms:pages folder=k_folder_name>
            <cms:redirect k_page_link />
        </cms:pages>
    </cms:folders>
</cms:if>

<!-- folder view -->
<cms:if k_is_folder>
    <cms:pages folder=k_folder_name >
        <cms:redirect k_page_link />
    </cms:pages>
</cms:if>

<!-- page view -->
<cms:if k_is_page>
    <!-- Sub navigation by folders (level 1) -->
    <ul>
    <cms:folders depth='1' orderby='weight'>
        <li><a href="<cms:show k_folder_link />" <cms:if k_page_foldername=k_folder_name>class="current"</cms:if>><cms:show k_folder_title /></a></li>
    </cms:folders>
    </ul>
   
    <!-- contents of the page -->
    <h1><cms:show k_page_title /></h1>
    <p>page contents here</p>
   
    <!-- Sub navigation by pages (level 2)-->
    (Contents of '<cms:show k_page_foldertitle />' folder)
    <ul>
        <cms:set current_page=k_page_name />
        <cms:pages folder=k_page_foldername>
            <li><a href="<cms:show k_page_link />" <cms:if k_page_name=current_page>class="current"</cms:if>><cms:show k_page_title /></a></li>   
        </cms:pages>
    </ul>
</cms:if>

Does this help?
Please let us know.

Thanks.
Wow, thank you so much KK - for taking the time to explain so clearly and providing me with the solution. Very elegant - and compact ... I think I was over-complicating things and getting in a tangle. This will be a great template for similar situations in the future - for me and others too I expect.
Yours gratefully, potato!!
My pleasure :)
You are always welcome, potato.
6 posts Page 1 of 1
cron