Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
I'm following a convention in my build where by I have main templates and sidebars for each (sidebars which typically have k_folders and archives).

Is it possible to do something like this:

Code: Select all
<cms:folders masterpage='<cms:show k_template_name />' orderby='title'>


So my file structure is like:

root/mytemplate.php
root/couch/snippets/cmytemplate_sidebar.php

example of what I tried in my sidebar on a news.php page:

Code: Select all
<h4><cms:show k_template_title /> Categories</h4>
<ul class="nav nav-pills nav-stacked">
<cms:folders masterpage='<cms: k_template_name />' orderby='title'>
   <li><a href="<cms:k_folder_link />"><cms:show k_folder_title /></a></li>
</cms:folders>
</ul>

<h4><cms:show k_template_title /> Archives</h4>
<ul class="nav nav-pills nav-stacked">
<cms:archives masterpage='"<cms:show k_template_name />"'>
   <li><a href="<cms: k_archive_link />"><cms:date k_archive_date format='F Y' /></a></li>
</cms:archives>
</ul>


I've read the docs on Smart Embeds and while they look great I'm not using them in this instance because I would prefer to be able to create a single sidebar instance for use across multiple cloned pages, it's about keeping the the core templates of the site as bare bones as possible so it can be easily re-cycled or skinned.
Patrick, the solution you have devised should work very well (In Couch, unlike EE (if I am not mistaken), you don't need to pass parameters to the embedded snippet - the snippet functions as if it was physically present on the calling page so all page variables are available).

As for the snippets you posted, they both have the same syntactical error -
See, the following are the only possible three ways a parameter (e.g. masterpage ) or a variable can be set
1. masterpage=my_template
Here the RHS (Right Hand Side value. In this case my_template) is not enclosed in any kind of quotes. This conveys to Couch that it is the name of a variable. So Couch searches for a variable named my_template and uses the value contained in that to set the masterpage.

2. masterpage='my_template'
Here, the RHS is enclosed within single-quotes. This conveys to Couch that it is a string (i.e. a fixed value). So, it goes ahead and sets the masterpage to 'my_template'.

3. masterpage="my_template"
This one is interesting. Here the RHS is using double-quotes. This conveys to Couch that it might come across some Couch code (i.e. Couch tags) in what is enclosed in the double-quotes. So it goes ahead and actually parses the string and executes any code contained within it and finally uses the result to set the masterpage parameter. The string might not contain any Couch tag in which case the result is the original string itself.
In our example "my_template" has no Couch tags so the result is 'my_template' and this what gets set in masterpage.

However, consider this:
masterpage="my_template<cms:show '_hello' />"
Now the result becomes 'my_template_hello' and this is used as the value of masterpage.

Apologies for this unsolicited dose of theory but now we'll be able to see what is wrong with your code.
This is what you used for the folders
<cms:folders masterpage='<cms: k_template_name />' orderby='title'>
I think you can see that this is scenario 2 - the single-quote will set the masterpage parameter to a literal string '<cms: k_template_name />'. There is certainly no masterpage with this name so the tag will output nothing.

The code you used for archives:
<cms:archives masterpage='"<cms:show k_template_name />"'>
Here you are using both quotes. This is an error (the outermost quote will take effect but the result will have the inner quotes appended to the name and hence will not match any templates).

The solution?
You have actually three:
1. <cms:archives masterpage=k_template_name >
k_template_name is indeed a variable that contains the name of the current template. So this will work ok.

2. <cms:archives masterpage="<cms:show k_template_name />" >
The double-quotes will make Couch execute the cms:show statement which will output the value of variable k_template_name. Works the same as above - just a little round about way to get the value of the variable.

3. Finally, you can even get away with this
<cms:archives >
Yup. No masterpage at all will make Couch use the current template which is what we want in your case.

Sorry again for the long post :) Hope this helps.
3. Finally, you can even get away with this
<cms:archives >
Yup. No masterpage at all will make Couch use the current template which is what we want in your case.


Brilliant! this is very handy! Thanks KK :D
@kk, it seems that it's always worth while trolling the forum. i was always wondering about the syntax you explained.
thanx for the explanation.
@cmdillon, Glad you found it useful but I was merely repeating what is explained in the docs :)
Please see http://www.couchcms.com/docs/concepts/s ... eters.html
I'm sure you'll find a few more useful tips there.
@kk: the funny thing is, i did read that page before, but i just breezed over it to find the relevant information for my problem at the time. :D
6 posts Page 1 of 1
cron