switch visibility of content block

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
User avatar
caigner
Forum Members
Forum Members
Posts: 46
Joined: Sun Aug 16, 2020 5:29 am

switch visibility of content block

Post 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
I am using CMSms 2.2.19
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1609
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: switch visibility of content block

Post 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.
Not getting the answer you need? CMSMS support options
Post Reply

Return to “Layout and Design (CSS & HTML)”