[SOLVED] Show content block on page only if not empty?

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
admsh
Forum Members
Forum Members
Posts: 93
Joined: Tue Aug 19, 2008 6:30 pm

[SOLVED] Show content block on page only if not empty?

Post by admsh »

I'm creating a layout with boxes, and in each box there is a content block. My problem is, that even when the content block is empty, the box shows up (each box is a DIV, with padding). I'm looking for a way to only show the box if the content block actually has content in it...

I've tried playing with this code, which I think doesn't work because I'm assigning a name after the argument is called... Any help would be so greatly appreciated:

Code: Select all

{if !empty($left_column_box)}
<div class="box">
{/if}
{content block="Left Column Box" assign="left_column_box"}
{if !empty($left_column_box)}
</div>
{/if}
Last edited by admsh on Sat Apr 30, 2011 6:25 pm, edited 1 time in total.
uniqu3

Re: Show content block on page only if not empty?

Post by uniqu3 »

Code: Select all

{content block="left-box" label="Left Column Box" assign="left_column_box"}
{if !empty($left_column_box)}
<div class="box">
{$left_column_box}
</div>
{/if}
admsh
Forum Members
Forum Members
Posts: 93
Joined: Tue Aug 19, 2008 6:30 pm

[SOLVED] Show content block on page only if not empty?

Post by admsh »

THANK YOU!!! works perfectly.
netfied

Re: [SOLVED] Show content block on page only if not empty?

Post by netfied »

Hi Goran,

I want to use advanced content to show or hide my content blocks idea i got from your bigbuzz.

I get a problem when i try to introduce the 3 content blocks to be activated by + sign i get
string(129) "Smarty error: [in tpl_body:24 line 192]: syntax error: unclosed tag \{if} (opened line 90). (Smarty_Compiler.class.php, line 317)"
Actually I want 3 content blocks and even copying your code does not get me anywhere. I will paste the code below.

Code: Select all

content block="Activate Sidebar" description='Enter + sign to enable this field, with - this field is disabled in the frontend' oneline="true" size="1" default="-" assign="sidebar" page_tab='Sidebar Options'}{if empty($sidebar)}{assign var="sidebar" value="+"}{/if}</p>
 <p>{content block="Display Three Blocks in Content" description='Enter + sign to enable this field, with - this field is disabled in the frontend' oneline="true" size="1" default="-" assign="contentblocks" page_tab='Page Options'} {if empty($contentblocks)}{assign var="contentblocks" value="+"}{/if}
   <!-- start pageHeader -->                      
 </p>
 {if $sidebar == "+"}              
      <div class="pageSidebar">
        <p>{if $sidenav == "+"}</p>
        <p>{* Showing Content Blocks *}
          {capture assign='fblocktitle'}{content block='First Block Title' description='This is Title field for first block' wysiwyg="false" oneline="true" page_tab='Page Options'}{/capture}
          {capture assign='fblockcontent'}{content block='First Block Content' description='By entering some text in this field, a content block with 1/3 of the page width will be displayed' page_tab='Page Options'}{/capture}
          {capture assign='sblocktitle'}{content block='Second Block Title' description='This is Title field for second block' wysiwyg="false" oneline="true" page_tab='Page Options'}{/capture}
          {capture assign='sblockcontent'}{content block='Second Block Content' description='By entering some text in this field, a content block with 1/3 of the page width will be displayed' page_tab='Page Options'}{/capture}
          {capture assign='tblocktitle'}{content block='Third Block Title' description='This is Title field for third block' wysiwyg="false" oneline="true" page_tab='Page Options'}{/capture}
          {capture assign='tblockcontent'}{content block='Third Block Content' description='By entering some text in this field, a content block with 1/3 of the page width will be displayed' page_tab='Page Options'}{/capture}
          {if $contentblocks == "+"}
          <!-- start infoBlockGroup -->
          {if ($fblocktitle)&&($fblockcontent)} </p>
</div>                   
      <div class="pageContentSide"><div class="pageContent">
        <div class="infoBlockGroup">
           <h3>{$fblocktitle}</h3>                                       
            <div class="infoBlockGroupInner">
            {$fblockcontent}                                
            </div>                                 
        </div>{/if}{if ($sblocktitle)&&($sblockcontent)}                                 
          <div class="infoBlockGroup">
           <h3>{$sblocktitle}</h3>                                       
            <div class="infoBlockGroupInner">
            {$sblockcontent}                                
            </div>                                 
          </div>{/if}{if ($tblocktitle)&&($tblockcontent)}                                 
          <div class="infoBlockGroup last">
           <h3>{$tblocktitle}</h3>                                       
            <div class="infoBlockGroupInner">
            {$tblockcontent}                                
            </div>                                 
          </div>{/if}                                 
          <div class="clear">                          
          </div>                                 
          <!-- end infoBlockGroup -->{/if}                               
uniqu3

Re: [SOLVED] Show content block on page only if not empty?

Post by uniqu3 »

Error says that you are missing closing {/if} somewhere.

In your pasted sample you are missing opening { but maybe this was just copy/paste probleme when pasting here :)
{content block="Activate Sidebar" description='Enter + sign to enable this field, with - this field is disabled in the frontend' oneline="true" size="1" default="-" assign="sidebar" page_tab='Sidebar Options'}{if empty($sidebar)}{assign var="sidebar" value="+"}{/if}</p>


But to get it easily working you can do it like this:

Code: Select all

<!-- usually i place optional template chunks like this somewhere after </__body> this will work only with AdvancedContent as you can see below i use parameter "dropdown" with Yes or No, default {content} tag doesn't have dropdown parameter -->
{content block="show-blocks" block_type="dropdown" items="Yes|No" default="No" description='Do you want to show three content block?' oneline="true" size="20" assign="three-blocks" page_tab="Optional Blocks"}

<!-- now somewhere in template where your blocks should show use this -->
{if $three-blocks == "Yes"} 
{* first one *}
{content block="frist" label="Content of first block" page_tab="Optional Block"}
{* second one *}
{content block="second" label="Content of second block" page_tab="Optional Block"} 
{* third one *}
{content block="third" label="Content of third block" page_tab="Optional Block"}  
{* end optional *}
{/if}
netfied

Re: [SOLVED] Show content block on page only if not empty?

Post by netfied »

thanks alot!!
You are God sent
netfied

Re: [SOLVED] Show content block on page only if not empty?

Post by netfied »

Hi,

few hitches here, first when i disable the content block on the backend they are still visible on the front end.

Second how am i able to disable individual content block?

finally how do i wrap each of the content block in a tag to style them in css?
netfied

Re: [SOLVED] Show content block on page only if not empty?

Post by netfied »

Just to help someone else
{content block="show_first" label="Show first block" oneline="true" size="1" default="-" assign="get_first" page_tab='Optional Blocks'}{if empty($get_first)}{assign var="get_first" value="+"}{/if}
{content block="show_second" label="Show second block" oneline="true" size="1" default="-" assign="get_second" page_tab='Optional Blocks'}{if empty($get_second)}{assign var="get_second" value="+"}{/if}

<!-- then somewhere in your template -->

{if $get_first == "+"}
<div class="something">
{content block="first_content" label="Content for first Block" page_tab='Optional Blocks'}
</div>
{/if}

{if $get_second == "+"}
<div class="something2">
{content block="second_content" label="Content for second Block" page_tab='Optional Blocks'}
</div>
{/if}
This worked..Thanks To Goran

fine for the time being bt sooner I gona need a column for title and another to input read more link. great tho!!

following the success in http://www.aeromarine.co.ke
I'm going to implement this in http://www.netfied.com and many others of my clients sites.
JM6891
Forum Members
Forum Members
Posts: 150
Joined: Thu Mar 18, 2010 2:35 pm

Re: [SOLVED] Show content block on page only if not empty?

Post by JM6891 »

Thanks for the tip on showing div only if content is entered! Perfect!
Post Reply

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