Forum for discussing general topics related to Couch.
7 posts Page 1 of 1
Hey guys! First, thank you very much for the amazing and easy-to-use thing! Its trully amazing)

Wanted to ask, is there a way to set up footer or header as a page editable like a separate page, not as a snippet?
Thank you in advance!
Hi :)

For such sections that are common to almost all the templates of the site (e.g. header, footer, sidebar etc.), the standard way in Couch for making them user editable is by defining their editable regions in a separate non-clonable template (e.g. named 'globals.php').

Since we can always show values of any template in any other template, we can place the code fetching values from this globals.php template (i.e. <cms:pages masterpage='globals.php'>) in a snippet and embed that in the other templates.

You can find details of this technique in our tutorial -
https://docs.couchcms.com/tutorials/por ... bal-values

I am sure you'll be able to adapt it to suit your use-case.

Hope this helps.
KK wrote: Hi :)

For such sections that are common to almost all the templates of the site (e.g. header, footer, sidebar etc.), the standard way in Couch for making them user editable is by defining their editable regions in a separate non-clonable template (e.g. named 'globals.php').

Since we can always show values of any template in any other template, we can place the code fetching values from this globals.php template (i.e. <cms:pages masterpage='globals.php'>) in a snippet and embed that in the other templates.

You can find details of this technique in our tutorial -
https://docs.couchcms.com/tutorials/por ... bal-values

I am sure you'll be able to adapt it to suit your use-case.

Hope this helps.


I got this, thanks!
But what if I want to add a repeatable option to globals? What code to insert?
Do i add gobals.php file to core or couch folder?

What a added in globals file

Code: Select all
<?php require_once ("couch/cms.php"); ?>
<cms:template title ='Chinese menu' executable='0'>

<cms:repeatable name="chinese_product_menu" label='Product menu list' stacked_layout='1'>
    <cms:editable name='chinese_product_name' label='Product title' type='text' />
    <cms:editable name='chinese_product_link' label='Product link' desc='Type page link here' type='text' />
</cms:repeatable>

</cms:template>
<?php COUCH::invoke(); ?>   


What I added in template file

Code: Select all
<!-- sub-menu start-->
<ul class="sub-menu">
                                   
<li><a href="<cms:get_custom_field 'chinese_product_link' masterpage='globals.php' />"><cms:get_custom_field 'chinese_product_name' masterpage='globals.php' /></a></li>
                                                                        
</ul>
<!-- sub-menu end-->
Do i add gobals.php file to core or couch folder?

All templates are added to the site folder itself (and *not* in the 'couch' folder).

After placing your globals.php in the site root make sure to visit it on the front-end as super-admin to register it.

Coming to the code where you use data entered into globals.php -
Since you are using 'repeatable region', your code would need to be modified as follows -
Code: Select all
<!-- sub-menu start-->
<ul class="sub-menu">

    <cms:pages masterpage='globals.php' limit='1'>
        <cms:show_repeatable 'chinese_product_menu'>
            <li>
                <a href="<cms:show chinese_product_link />"><cms:show chinese_product_name /></a>
            </li>
        </cms:show_repeatable>
    </cms:pages>
                                                                       
</ul>
<!-- sub-menu end-->

Notice above how we are using <cms:pages> to get data from globals.php and then using <cms:show_repeatable> within it to loop through the repeatable region and output its rows.

Hope this helps.
Thank you very much)
You are welcome :)
7 posts Page 1 of 1