Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello.

I`m trying to display content based on different urls.

for example:

I have some editable text fields
<editable name='Title_abc ...>
<editable name='Title_xyz ...>
<editable name='Title_cvc ...>
...
When a user opens page contact.php?p='xyz' I want to show the text in editable field xyz

<cms:show Title_xyz />

again when user opens contact.php?p='cvc' I want to show <cms:show Title_cvc />

Is this possible?
Hi,

One can always use a series of cms:if/cms:else statements to select the right variable.
However, the best way would be to dynamically piece together the variable name depending on the value passed through the 'p' parameter of URL.

This is how we do that -
Code: Select all
<cms:set my_suffix="<cms:gpc 'p' method='get' />" />

<cms:get "Title_<cms:show my_suffix />" />

In the code above, the first statement gets the value of 'p'.
The second statement then appends that value to 'Title_' to get the variable name and uses cms:get to show that variable's value.

Notice that instead of using cms:show, we are using cms:get that can work with strings (thus allowing to dynamically create variable names. as in our case).
You might want to see this tag's documentation at - http://www.couchcms.com/docs/tags-reference/get.html

Hope this helps.
Thank you! It works perfectly !!
3 posts Page 1 of 1
cron