Forum for discussing general topics related to Couch.
8 posts Page 1 of 1
...
Can I create folders within a folder view template?

ex:

Dining Table (main folder)
- submenu (sub folder)
- submenu2 (sub folder)

I have no idea how to code this part....
Hi,

Folders support unlimited hierarchy so what you are asking for is staple fare.
To create nested folders, simply specify the right existing folder as parent of the folder being created.

To list the folders on the front-end in an hierarchical manner (so as to create a nested-menu, for example), please see the following - http://docs.couchcms.com/concepts/using ... om-folders

The same docs page also show how to mark as selected all parent folders of the current folder being visited - http://docs.couchcms.com/concepts/using ... d-children

Does this help?
Thanks KK, it you are being really helpful! It's a good tips.

I have created the menu, but the structure seems a little weird:

The code structure generate by CMS

Code: Select all
<ul>
   <!-- First main menu -->
   <li id="active">
      <a href="http://localhost/test6/products.php?f=5">123(0)</a>
         <ul>
            <li id="active">
               <a href="http://localhost/test6/products.php?f=7">789(1)</a>
            </li>
         </ul>
   </li>
                               
    <!-- Second main menu -->                       
   <li>
      <a href="http://localhost/test6/products.php?f=6">456(0)</a>
   </li>
</ul>


The original html source code:

Code: Select all
<ul>
   <!-- First main menu -->
   <li id="active">
        <a href="#">123(0)</a>
         <ul>
            <li id="active">
               <a href="http://localhost/test6/products.php?f=7">789(1)</a>
            </li>
         </ul>
   </li>
                               
    <!-- Second main menu -->                       
   <li>
      <a href="http://localhost/test6/products.php?f=6">456(0)</a>
   </li>
</ul>


CMS code:

Code: Select all
<div class="submenu">
                            <cms:if k_is_page || k_is_folder >
                                <cms:if k_folder_name ><cms:set current_folder=k_folder_name /></cms:if>
                                <cms:if k_page_foldername ><cms:set current_folder=k_page_foldername /></cms:if>
                            </cms:if>
                            <cms:folders hierarchical='1' extended_info='1'>
                                <cms:if k_level_start ><UL></cms:if>
                                <cms:if k_element_start >
                           
                                    <cms:set my_class='' />
                                    <cms:if "<cms:is_ancestor parent=k_folder_name child=current_folder />" >
                                        <cms:set my_class='id="active"' />
                                    </cms:if>
                           
                                    <LI <cms:show my_class />>
                                    <a href="<cms:show k_folder_link/>"><cms:show k_folder_title/></a>
                                </cms:if>
                                <cms:if k_element_end ></LI></cms:if>
                                <cms:if k_level_end ></UL></cms:if>
                            </cms:folders>
                            </div>


I got one problem. If the parent folder got child folders, I do not want it to link to any page, if user click on it, it will only expand child folders. But for the other parent folders that without child folders will link to related page. Just like I do in second code example.

What should I do on this?
If the parent folder got child folders, I do not want it to link to any page..

To do that, please modify the following statement in your code -
Code: Select all
<a href="<cms:show k_folder_link/>"><cms:show k_folder_title/></a>

to this -
Code: Select all
<a href="<cms:if k_folder_immediate_children>#<cms:else /><cms:show k_folder_link/></cms:if>"><cms:show k_folder_title/></a>

Hope it helps.
Thanks. It worked.

But....

The page of parent folder with child folders is created. How can I redirect the page to first child folder page?

Let say the page:

http://www.xxx.com/Products.php (parent folder / main page),
http://www.xxx.com/Products/table.php (child folder / sub-page).

This is the current redirect code:

Code: Select all
<!-- if this is NOT a folder -->
            <cms:if k_is_home>
                <!-- will listing folders -->
                <cms:folders>
                    <!-- will redirect to folder -->
                    <cms:redirect url="<cms:show k_folder_link/>" />
                </cms:folders>
            </cms:if>


Everytime I enter the main page, it will show a blank page. How can I make it redirect the page to first child folder page (first sub-page)? the redirect code should only work for parent folder with child folders, for the other parent folder without child folder should just link to corresponding page without redirect.

Big thanks for your assistant.
Before redirecting we can check the 'level' of the folder being iterated as follows (please note the addition of hierarchical='1' to cms:folders)
Code: Select all
<cms:if k_is_home>
    <!-- list folders -->
    <cms:folders hierarchical='1'>
        <!-- and redirect to the first folder that is not top-level -->
        <cms:if k_level='1'>
            <cms:redirect url="<cms:show k_folder_link />" />
        </cms:if>
    </cms:folders>
</cms:if>

Alternatively, you could check if the folder is not empty (i.e. has some pages within) before redirecting to it as follows -
Code: Select all
<cms:if k_is_home>
    <!-- list folders -->
    <cms:folders hierarchical='1'>
        <!-- and redirect to the first folder found with pages within -->
        <cms:if k_folder_pagecount>
            <cms:redirect url="<cms:show k_folder_link />" />
        </cms:if>
    </cms:folders>
</cms:if>

TIP:
As you can see, the answer to both your previous questions was simply checking for some variable before taking the action. To know which variables can be helpful to you, you can place a <cms:dump /> instead of the action and you'll get a list of all variables available at that point. Try replacing cms:redirect line with cms:dump and see this.

Hope it helps.
Problem solved. Thanks.

I will keep purchase your product and hope to see the new version release soon.
8 posts Page 1 of 1
cron