[SOLVED] Hide empty content blocks

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
newagekat
Forum Members
Forum Members
Posts: 161
Joined: Mon Feb 06, 2006 6:06 pm

[SOLVED] Hide empty content blocks

Post by newagekat »

Hi:

I'm using v1.8.

I would like to add a custom content block to a template.  Since the divs surrounding the block is styled with height and colour, I would like to add code to the template that hides the block if it contains NO entry and show if it does. 

something like this:

if content block is not empty {

{content block="optional extra heading" oneline="true"}
{content block="sidebarContent" label="Optional Extra Stuff"}

} else
{
}
end if

I'm not very good with syntax nor do i know smarty very well.  Can anyone help?
Last edited by newagekat on Mon Jul 26, 2010 9:03 pm, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm

Re: Hide empty content blocks

Post by Jos »

Regarding Tips & Tricks:
calguy1000 wrote: Any posts in this forum should be solutions to answers faced by our users, posted by our users for the benefit of others.

There should be no 'questions' as the first post of any topic in this forum.
Regarding to your question:

Code: Select all

{content block="optional extra heading" oneline="true" assign='content_heading'}
{if !empty($content_heading)}
<div class="boxwrap" style="width: 180px;">
<div class="boxhg">{content block="optional extra heading" oneline="true"}</div>
<div class="box">{content block="sidebarContent" label="Optional Extra Stuff"}</div>
</div>
{else}
...
{/if}
newagekat
Forum Members
Forum Members
Posts: 161
Joined: Mon Feb 06, 2006 6:06 pm

Re: Hide empty content blocks

Post by newagekat »

my mistake, I'm sorry.

can you move the post somewhere else?  i have more questions.  thank you.
newagekat
Forum Members
Forum Members
Posts: 161
Joined: Mon Feb 06, 2006 6:06 pm

Re: Hide empty content blocks

Post by newagekat »

Hi:

I've added the following code to my template:

Code: Select all

{content block="box4hdg" assign='box4hdg'}
{content block="box4" assign="box4"}
{if !empty($box4hdg)}
<div class="boxwrap">
<div class="boxhg">{content block="box4hdg" label="Optional Heading 1" oneline="true"}</div>
<div class="box">{content block="box4" label="Optional Content 1"}</div>
</div>
{else}

{/if}
At first I had some parsing error that said it there was either a duplicate {content} block or one was missing.  The edit page is now missing all fields below Parent.  I removed the code from the template, saved the test page, and logged out of admin.  When I logged back in, i re-entered the code in the template and saved.  i then edited the test page, which now opened with all fields present, and tried saving with and without content in my custom content blocks.  IT WORKED!  

I now apply the code to a template that exists, and I get this error:

Code: Select all

[color=red]An error occurred parsing content blocks (perhaps duplicated block names)[/color]
and every filed below the parent dropdown is not visible at all.
???
Last edited by newagekat on Mon Jul 26, 2010 8:46 pm, edited 1 time in total.
owr_bgld

Re: Hide empty content blocks

Post by owr_bgld »

newagekat wrote: {else}

{/if}
just4info: you don't need the {else} if you don't have any code or text (means nothing) between {else} and {/if}
Last edited by owr_bgld on Mon Jul 26, 2010 9:27 pm, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm

Re: Hide empty content blocks

Post by Jos »

Make it:

Code: Select all

{content block="box4hdg" label="Optional Heading 1" oneline="true" assign='box4hdg'}
{content block="box4" label="Optional Content 1" assign='box4'}
{if !empty($box4hdg)}
<div class="boxwrap">
<div class="boxhg">{$box4hdg}</div>
<div class="box">{$box4}</div>
</div>
{/if}
At first I had some parsing error that said it there was either a duplicate {content} block or one was missing.  The edit page is now missing all fields below Parent.  I removed the code from the template, saved the test page, and logged out of admin.  When I logged back in, i re-entered the code in the template and saved.  i then edited the test page, which now opened with all fields present, and tried saving with and without content in my custom content blocks.  IT WORKED!  

I now apply the code to a template that exists, and I get this error:

Code: Select all

[color=red]An error occurred parsing content blocks (perhaps duplicated block names)[/color]
and every filed below the parent dropdown is not visible at all.
???




[/quote]
newagekat
Forum Members
Forum Members
Posts: 161
Joined: Mon Feb 06, 2006 6:06 pm

Re: Hide empty content blocks

Post by newagekat »

JOS:

thank you, that WORKED!  ;D
Post Reply

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