Page 1 of 1

switch visibility of content block

Posted: Fri Jun 11, 2021 1:13 pm
by caigner
Hi!

Depending on the status of my content, I want to hide the <article> block. So I added a simple Smarty if-statement:

Code: Select all

<article {if empty($content) }style="display: none;"{/if}>
  {content}
</article>
Unfortunately it does not work. The <article> block is always hidden, eventhough my content has text:

Code: Select all

<article style="display: none;">
   Lorem ipsum ... 
</article>
I also tried it like this:

Code: Select all

<article {if !isset($content) }style="display: none;"{/if}>
  {content}
</article>
Same result. Can anybody shed some light on how I can switch the visibility of my <article> block depending on whether {content} has some text in it?

Thanks!
Christian

Re: switch visibility of content block

Posted: Fri Jun 11, 2021 3:05 pm
by DIGI3
{$content} isn't the same as {content}, unless you assign it first.

I'd probably do something like this:

Code: Select all

{$content={content}}
{if $content|strip:''|strip_tags:false}
  <article>{$content}</article>
{/if}
The |strip and |strip_tags will hide it if there's just an empty <p></p> and/or blank space in case it got left in by the wysiwyg.

No need for inline styles, which are inefficient.