Page 1 of 1
[SOLVED] Show content block on page only if not empty?
Posted: Sat Apr 30, 2011 3:20 pm
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}
Re: Show content block on page only if not empty?
Posted: Sat Apr 30, 2011 4:48 pm
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}
[SOLVED] Show content block on page only if not empty?
Posted: Sat Apr 30, 2011 6:25 pm
by admsh
THANK YOU!!! works perfectly.
Re: [SOLVED] Show content block on page only if not empty?
Posted: Mon May 09, 2011 8:02 am
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}
Re: [SOLVED] Show content block on page only if not empty?
Posted: Mon May 09, 2011 9:19 am
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}
Re: [SOLVED] Show content block on page only if not empty?
Posted: Mon May 09, 2011 10:31 am
by netfied
thanks alot!!
You are God sent
Re: [SOLVED] Show content block on page only if not empty?
Posted: Mon May 09, 2011 4:05 pm
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?
Re: [SOLVED] Show content block on page only if not empty?
Posted: Tue May 31, 2011 7:25 pm
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.
Re: [SOLVED] Show content block on page only if not empty?
Posted: Thu Dec 22, 2011 10:44 am
by JM6891
Thanks for the tip on showing div only if content is entered! Perfect!