Page 1 of 2
Testing to see if a content block exists / contains content
Posted: Thu Nov 10, 2005 1:20 am
by megwoo
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!!!
Re: Testing to see if a content block exists / contains content
Posted: Thu Nov 10, 2005 10:51 am
by Ted
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}
Re: Testing to see if a content block exists / contains content
Posted: Thu Nov 10, 2005 5:43 pm
by megwoo
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!
Re: Testing to see if a content block exists / contains content
Posted: Thu Nov 10, 2005 8:12 pm
by Ted
Ah, yeah. Sorry about that.
No problem.
Re: Testing to see if a content block exists / contains content
Posted: Wed Dec 07, 2005 7:54 pm
by Dr. J
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
Re: Testing to see if a content block exists / contains content
Posted: Thu Dec 08, 2005 3:14 am
by Ted
Make sure this is all on one line:
Code: Select all
{capture name=contentoutput}{content block='info'}{/capture}
. It's picking up the newlines and the output will never be empty.
Re: Testing to see if a content block exists / contains content
Posted: Thu Dec 08, 2005 10:32 am
by Dr. J
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!
Re: Testing to see if a content block exists / contains content
Posted: Thu Dec 08, 2005 6:48 pm
by Dr. J
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
Code: Select all
{capture assign=foobar}{content block='info'}{/capture}
{if $foobar|count_characters >0}HTML TO BE SHOWN{/if}
but either way the conditional statement returns true...
pls help - I'm loosing my mind here

Re: Testing to see if a content block exists / contains content
Posted: Thu Dec 08, 2005 7:09 pm
by Ted
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
Posted: Thu Dec 08, 2005 7:43 pm
by Dr. J
That's the problem...
Code: Select all
{capture assign=foobar}{content block='info'}{/capture}
Start:{$foobar}:End
{if $foobar ne ""}
We've got content!<br>
{/if}
$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?
Re: Testing to see if a content block exists / contains content
Posted: Tue Dec 13, 2005 9:47 pm
by Jacob Hage
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
Re: Testing to see if a content block exists / contains content
Posted: Wed Dec 14, 2005 1:14 pm
by Ted
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
Posted: Sat Dec 17, 2005 10:55 am
by fadum
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
Re: Testing to see if a content block exists / contains content
Posted: Sun Dec 18, 2005 10:20 am
by fadum
Ive tried all methods mentioned and allways get "True"
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
Posted: Mon Dec 19, 2005 1:26 am
by fadum
Does anyone know another way to achieve this?? its driving me mad
Thanks