Testing to see if a content block exists / contains content
Testing to see if a content block exists / contains content
I'm a newbie to CMS made simple, so I suspect this may be an easy question--I just couldn't find an answer in the forums...
I'm trying to display special html formatting in a template ONLY if a content block exists / contains text, so I need to figure out how to test for a content block.
My content block is named "spotlight" and I've been trying things like this:
{if isset(content block="spotlight")} {/if}
{if isset($spotlight)} {/if}
{if $spotlight} {/if}
But nothing has worked. Does anyone know how I can refer to the "spotlight" content block from within a template?
THANK YOU!!!
I'm trying to display special html formatting in a template ONLY if a content block exists / contains text, so I need to figure out how to test for a content block.
My content block is named "spotlight" and I've been trying things like this:
{if isset(content block="spotlight")} {/if}
{if isset($spotlight)} {/if}
{if $spotlight} {/if}
But nothing has worked. Does anyone know how I can refer to the "spotlight" content block from within a template?
THANK YOU!!!
Re: Testing to see if a content block exists / contains content
These kinds of tricks won't work in 0.10.3/4 because of the way that the content tag used to be handled. However... 0.11beta4 will allow it, since there was a big overhaul of how smarty does it's thing.
The other option is to do something like....
{capture name='contentoutput'}{content block="blah"}{/capture}
{if smarty.capture.contentoutput ne ''}{/if}
The other option is to do something like....
{capture name='contentoutput'}{content block="blah"}{/capture}
{if smarty.capture.contentoutput ne ''}{/if}
Re: Testing to see if a content block exists / contains content
Wishy, Thanks for your prompt reply!
At first I couldn't get it to work, but then I added a '$':
{if $smarty.capture.contentoutput ne ''}{/if}
It works beautifully. Thanks!
At first I couldn't get it to work, but then I added a '$':
{if $smarty.capture.contentoutput ne ''}{/if}
It works beautifully. Thanks!
Re: Testing to see if a content block exists / contains content
Ah, yeah. Sorry about that. 
No problem.

No problem.
Re: Testing to see if a content block exists / contains content
hmm... I'm trying the same thing but it doesn't work - am I doing something wrong?
{capture name=contentoutput}
{content block='info'}
{/capture}
{if $smarty.capture.contentoutput ne ''}
{$smarty.capture.contentoutput}
{/if}
regardless of the contents of the block 'info' the section within {if}{/if} is shown.
pls help
{capture name=contentoutput}
{content block='info'}
{/capture}
{if $smarty.capture.contentoutput ne ''}
{$smarty.capture.contentoutput}
{/if}
regardless of the contents of the block 'info' the section within {if}{/if} is shown.
pls help
Re: Testing to see if a content block exists / contains content
Make sure this is all on one line: . It's picking up the newlines and the output will never be empty.
Code: Select all
{capture name=contentoutput}{content block='info'}{/capture}
Re: Testing to see if a content block exists / contains content
Hi Wishy,
I'v tried putting the code in one line but the result is the same: The conditional section is shown whether there is content or not.
Btw - I'm using CMSMS 0.11.1
Cheers!
I'v tried putting the code in one line but the result is the same: The conditional section is shown whether there is content or not.
Btw - I'm using CMSMS 0.11.1
Cheers!
Re: Testing to see if a content block exists / contains content
Do you have any idea why it doesn't work for me?
I think it might be a caching issue. It doesn't matter if I type something in the content block or if I leave it empty. The {if} statement returns true.
I've tried using {capture name=xxx} and {capture assign=xxx}
I've also tried to add |count_characters and then change the conditional statement to
but either way the conditional statement returns true...
pls help - I'm loosing my mind here
I think it might be a caching issue. It doesn't matter if I type something in the content block or if I leave it empty. The {if} statement returns true.
I've tried using {capture name=xxx} and {capture assign=xxx}
I've also tried to add |count_characters and then change the conditional statement to
Code: Select all
{capture assign=foobar}{content block='info'}{/capture}
{if $foobar|count_characters >0}HTML TO BE SHOWN{/if}
pls help - I'm loosing my mind here

Re: Testing to see if a content block exists / contains content
So, I guess the question is... what is in $foobar?
Code: Select all
{capture assign=foobar}{content block='info'}{/capture}
Start:{$foobar}:End
Re: Testing to see if a content block exists / contains content
That's the problem...
$foobar contains the content from the content block but "We've got content!" is apparently being displayed regardless of the content of $foobar!?
On one page it says:
Start:hello world:End
We've got content!
And on the other (empty) page it says:
Start::End
We've got content!
Am I missing something?
Code: Select all
{capture assign=foobar}{content block='info'}{/capture}
Start:{$foobar}:End
{if $foobar ne ""}
We've got content!<br>
{/if}
On one page it says:
Start:hello world:End
We've got content!
And on the other (empty) page it says:
Start::End
We've got content!
Am I missing something?
Re: Testing to see if a content block exists / contains content
Has anyone else experienced this problem? or am I doing something wrong?
Guess it must be either a bug or a whitespace problem...
Wishy, can you confirm whether if it's a bug or perhaps replicate my setup?
Thanks
Guess it must be either a bug or a whitespace problem...
Wishy, can you confirm whether if it's a bug or perhaps replicate my setup?
Thanks
Re: Testing to see if a content block exists / contains content
I don't have much time at the moment to investigate this. Though, quickly thinking, maybe a strip modifier is in order. Just in case there is a weird character or something in there.
Code: Select all
{capture assign=foobar}{content block='info'|strip}{/capture}
Start:{$foobar}:End
{if $foobar ne ""}
We've got content!<br>
{/if}
Re: Testing to see if a content block exists / contains content
There seems to be lots of examples in this topic, can someone tell me what i should use in 0.11.1?
i need to display only if content exists
Thanks
i need to display only if content exists
Thanks
Re: Testing to see if a content block exists / contains content
Ive tried all methods mentioned and allways get "True" 
even with strip i get:
Start::End We've got content!
Any ideas please?

even with strip i get:
Start::End We've got content!
Any ideas please?
Re: Testing to see if a content block exists / contains content
Does anyone know another way to achieve this?? its driving me mad
Thanks
Thanks