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?
[SOLVED] Hide empty content blocks
[SOLVED] Hide empty content blocks
Last edited by newagekat on Mon Jul 26, 2010 9:03 pm, edited 1 time in total.
Re: Hide empty content blocks
Regarding Tips & Tricks:
Regarding to your question: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.
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
my mistake, I'm sorry.
can you move the post somewhere else? i have more questions. thank you.
can you move the post somewhere else? i have more questions. thank you.
Re: Hide empty content blocks
Hi:
I've added the following code to my template:
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: and every filed below the parent dropdown is not visible at all.

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}
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]

Last edited by newagekat on Mon Jul 26, 2010 8:46 pm, edited 1 time in total.
Re: Hide empty content blocks
just4info: you don't need the {else} if you don't have any code or text (means nothing) between {else} and {/if}newagekat wrote: {else}
{/if}
Last edited by owr_bgld on Mon Jul 26, 2010 9:27 pm, edited 1 time in total.
Re: Hide empty content blocks
Make it:
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: and every filed below the parent dropdown is not visible at all.

[/quote]
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}
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]

[/quote]
Re: Hide empty content blocks
JOS:
thank you, that WORKED!
thank you, that WORKED!
