phptemplatescouch-cms

Couch CMS: if template== then do something


I'm looking into a bunch of different lightweight CMS and Couch CMS is up. It is so incredibly straight forward, I love it! Great for clients that now and then want to add or edit content.

For a website, I include a footer into different templates, but on one of those templates I want the footer to be different from the others.

So all the templates contain the following php:

<?php require_once dirname(__FILE__) . "/includes/footer-scripts.html"; ?>

And footer-scripts.html contains the following:

<script src="<cms:show k_site_link />js/global/jquery-1.11.1.min.js"></script> 
<cms:if k_page_name=='users' >
    <script src="<cms:show k_site_link />js/global/imagesloaded.min.js"></script>
</cms:if>
<script src="<cms:show k_site_link />js/scripts.js"></script>

Hoping that when the template "users" is used, an additional script is loaded into the page. Unfortunately, this does not work. I do not know why though, because the template "users.php" contains

<cms:template title="Users"/>

So how do you target a specific template with a conditional?


Solution

  • I think you should use 'k_template_name' instead of 'k_page_name'. The value to test would be 'users.php' (assuming that is the name of your template).

    <cms:if k_template_name='users.php' >
        <script src="<cms:show k_site_link />js/global/imagesloaded.min.js"></script>
    </cms:if>
    

    An easy way of knowing which variables to use at any location is to place

    <cms:dump />
    

    or

    <cms:dump_all />
    

    at that location. You'll get to see a list of all available variables with their values.