Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
Hello,

I'm trying to append a class to the HTML, based on the template name.

For example: If template = index.php add class="pg-home" else if template = news.php add class="pg-news"

At the moment i'm adding it like this:

class="<cms:if k_template_name=='index.php'>pg-home</cms:if> <cms:if k_template_name=='news.php'>pg-news</cms:if>

But wondered if this was the 'right' approach to take? Someone may have a better way, as this method becomes quite hard to read (code wise).

Thanks in advance :)
Hi Steve,

Your approach is perfectly valid.
However, If the readability issue bothers you, you can modify the approach a little to make it as follows -
Code: Select all
<cms:capture into='my_class' 'global'>
    <cms:if k_template_name=='index.php'>pg-home</cms:if>
    <cms:if k_template_name=='news.php'>pg-news</cms:if>
    <cms:if k_template_name=='contact.php'>pg-contact</cms:if>
</cms:capture>

<BODY class="<cms:show my_class />">
..

Hope it helps.
Perfect, thankyou very much!
3 posts Page 1 of 1