Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I have the following code:

Code: Select all
<cms:editable name='main_video' label='YouTube Embed Code' type='textarea' no_xss_check='1' />

<cms:if "<cms:not_empty main_video />" >
Do something...
</cms:if>


That doesn't work. I had to change it to:
Code: Select all
<cms:if main_video>
Do something...
</cms:if>

For it to work.

Just wanted to point this out cause I don't think it's meant to be this way.

Thanks!
Hi :)

I think I can see the reason for this apparent anomalous behaviour.

If you take a look at this tag's documentation (http://docs.couchcms.com/tags-reference/not_empty.html), you'll see mentioned that it is primarily for use with 'richtext' region - the reason being that richtext, even though it appears to be empty, often puts in some HTML tags like <BR/> or <P> in its contents. To handle this, cms:not_empty tag strips out HTML tags and reports only the remaining textual content.

I think what could be happening in your case (seeing that you are using 'no_xss_check') is that the content you are inputting (likely some embed code) consists entirely of such HTML tags that do not have enclosed contents e.g. like this -
Code: Select all
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Once cms:not_empty strips off the HTML tags, nothing remains. Ergo the result you saw.

As mentioned in the above mentioned docs page, the following is the preferred (and a more direct) way of checking contents in non-richtext regions -
Code: Select all
<cms:if my_content >
   .. do something..
</cms:if>

Hope this helps.
Ah ok. I had looked at the documentation, but somehow missed that not_empty actually stripped away HTML tags.

Thanks!
3 posts Page 1 of 1