Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
I have a typical blog template with a richtext area that holds a story. There is also an RSS feed linked to this blog. The RSS feed uses the cms:pages tag to display stories in the feed.

Code: Select all
<cms:pages masterpage='stories.php'>

<item>
<title><cms:show k_page_title /></title>
<link><cms:show k_page_link /></link>
<pubDate><cms:date k_page_date format='l F j, Y H:i' /></pubDate>

<description>
<cms:html_encode>
    <cms:do_shortcodes><cms:show blog /></cms:do_shortcodes>
</cms:html_encode>
</description>
</item>

</cms:pages>

What I want to do is use a shortcode in the richtext field that will conditionally show code depending on whether the current page is the blog page or the RSS feed.

Code: Select all
[embed code='<cms:if k_template_name == "rss.php" >This is the Feed<cms:else />This is the Page</cms:if>']

The problem I'm having is finding the correct variable. From within the cms:pages loop, k_template_name returns the loop's masterpage, not the current template. How can I access the current template from within a cms:pages loop?

References
RSS Feed:
http://docs.couchcms.com/concepts/rss-feeds.html
Embed shortcode:
viewtopic.php?f=8&t=7950

@Tim, the <cms:pages> loop itself sets the k_template_name variable which effectively 'masks' or 'overshadows' the variable of the same name set by the main template. This makes the shortcode always pick up the inner variable.

One way to solve this would be to use a variable from the main template that would not be set again within the inner cms:pages loop. For example, we can do the following in rss.php template -
Code: Select all
<cms:set my_template_name='rss.php' scope='global' />

<cms:pages masterpage='stories.php'>

    [embed code='<cms:if my_template_name == "rss.php" >This is the Feed<cms:else />This is the Page</cms:if>']
   
</cms:pages>

In the code above, instead of k_template_name, we are using 'my_template_name'.
Please note that the modified shortcode would work on the other template because there this 'my_template_name' variable would not be set at all.

Would this help?

@KK I had the same idea after giving it some more thought.

That will work. Thanks for the help! :)
3 posts Page 1 of 1
cron