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

I would like to allow the user to show regions data inside a text area field.

Here's the line for that field:
Code: Select all
<cms:editable name='content' label='Content test' type='textarea' no_xss_check='1'/>


If I enter in the text area field :

Code: Select all
Hello <cms:show name/>


And click save, it will save it as is. But if I try to display that text area field, like this:

Code: Select all
<cms:show content/>


It will show:

Code: Select all
Hello


It won't display the "name" region, even if there is something in that "name" region in the admin for that page.
If I use a "richtext" field instead, it will show:
Code: Select all
Hello <cms:show name/>

But of course, I don't want it to show "<cms:show name/>", I want the content of that "name" field.

My guess is that it's not possible by default. Is there any way to achieve this?

Thanks!
There is a way to achieve this, of course. Maybe you missed this article http://docs.couchcms.com/tags-reference ... e-directly

Imho, users should never be able to enter arbitrary code in backend which would run in frontend. Please just forget about allowing them. The reason is not only security, of course. Such demand is a derivative of a bad design, as it usually stands..

There must be some other way to manage things without users learning syntax of cms commands, even though it is not difficult. Otherwise, if clients are expected to learn cms programming, why do they need you?
Thanks, I will check out this article.

In my case, this will be useful.
It will be used to create custom email template. Stuff like automatic notifications and more.
The user will be able to select from a relation field which email template he wants to use.

I won't get into all the details, but I'm glad there's a way to do it.

Thanks!
@larin555, I'll agree with @trendoman that granting such sweeping power to the end-user is only likely to end in something unpleasant.

The recommended way is that you create 'shortcodes' (http://docs.couchcms.com/miscellaneous/shortcodes.html) instead for the specific use-cases and then the user can use them as and when required.
A shortcode looks like a good idea.

I have tried this though:

Code: Select all
$FUNCS->register_shortcode( 'hello', 'hello_handler' );

function hello_handler( $params, $content=null ){
    return '<cms:pages masterpage="contracts.php"><cms:show k_page_title/></cms:pages>';
}


And nothing is being displayed from that shortcode when I enter "[hello]" somewhere.
Can I use regular Couch code and editables inside a shortcode?
I have changed the code inside the single quotes after "return" for html stuff and it worked. But doesn't seem to work for Couch related fields.

For example, how would I create a shortcode named [list] that would display all pages titles from the "contracts.php" page?
Again, I must be able to insert that shortcode in a text area region in the admin.

Thanks
If you do a view:source of your page, you should see the following string in it -
<cms:pages masterpage="contracts.php"><cms:show k_page_title/></cms:pages>

Of course, that is being treated as (invalid) HTML by the browser so nothing is being rendered.

Point is, we don't want to simply output the Couch code verbatim; rather, we want to *execute* that code and output the results.
For that you need to pass on your Couch code to $FUNCS->embed().

This technique is used by the "6. Obfuscate email" shortcode sample in the docs at http://docs.couchcms.com/miscellaneous/shortcodes.html. Tim's all-purpose shortcode also makes use of the technique (viewtopic.php?f=8&t=7950).

I am sure those samples will help you in creating the kind of shortcode you want.
6 posts Page 1 of 1
cron