Page 1 of 1
[SOLVED] Hide empty content blocks
Posted: Mon Jul 26, 2010 5:28 pm
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?
Re: Hide empty content blocks
Posted: Mon Jul 26, 2010 5:40 pm
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}
Re: Hide empty content blocks
Posted: Mon Jul 26, 2010 6:14 pm
by newagekat
my mistake, I'm sorry.
can you move the post somewhere else? i have more questions. thank you.
Re: Hide empty content blocks
Posted: Mon Jul 26, 2010 8:38 pm
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.

Re: Hide empty content blocks
Posted: Mon Jul 26, 2010 8:47 pm
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}
Re: Hide empty content blocks
Posted: Mon Jul 26, 2010 8:54 pm
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]
Re: Hide empty content blocks
Posted: Mon Jul 26, 2010 9:02 pm
by newagekat
JOS:
thank you, that WORKED!
