Page 1 of 1

[Solved] Hiding empty content block--dupe block names error?

Posted: Fri Feb 24, 2012 4:28 pm
by Samarama
Using CMSms 1.10.3, new install, no extra modules yet.

Trying to set up a 2/3-column template where the right-hand column (sidebar_right) only appears if there's content. I've got this basic logic, picked up from some similar questions in this forum:

{capture assign='testvar'}{content block='contents-rt' label='RIGHT Sidebar Content (optional)'}{/capture}
{if isset($testvar) && !empty($testvar)}
<div id="main" class="grid_6">
<div id="contentmain">
{content label="MAIN Content Area"}
</div>
</div>
<div id="sidebar_right" class="grid_3 omega">
<div id="contentright">
{$testvar}
</div>
</div>
{else}
<div id="main" class="grid_9 omega">
<div id="contentmain">
{content label="MAIN Content Area"}
</div>
</div>
{/if}

So basically the main content area should get wider if the right column has no content. Right column just would not appear at all.

When I try to add a new content page with this template, I get this:

An error occurred parsing content blocks (perhaps duplicated block names)

Also, none of the content areas are showing on the New Content page?

Seems like I am really close, but missing some important detail here. Suggestions, pointers, ideas anyone?

Thanks

Re: Hiding empty content block -- duplicate block names erro

Posted: Fri Feb 24, 2012 4:56 pm
by Jos
Replace this

Code: Select all

{capture assign='testvar'}{content block='contents-rt' label='RIGHT Sidebar Content (optional)'}{/capture}
with this

Code: Select all

{content block='contents-rt' label='RIGHT Sidebar Content (optional)' assign='testvar'}
{content label="MAIN Content Area" assign='maincontent'}
and the two occurrences of {content label="MAIN Content Area"} should then be replaced by

Code: Select all

{$maincontent}

Re: Hiding empty content block -- duplicate block names erro

Posted: Fri Feb 24, 2012 4:59 pm
by Wishbone
EDIT: Jos beat me to it. :)

Regardless of your logic, you must only have one content block of a given name. (including {content} without block= )

Also, you don't need {capture} around your block.

Try:

Code: Select all

{content label="MAIN Content Area" assign="main_content"}
{content block='contents-rt' label='RIGHT Sidebar Content (optional)' assign='testvar'}
{if isset($testvar) && !empty($testvar)}
<div id="main" class="grid_6">
<div id="contentmain">
{$main_content}
</div>
</div>
<div id="sidebar_right" class="grid_3 omega">
<div id="contentright">
{$testvar}
</div>
</div>
{else}
<div id="main" class="grid_9 omega">
<div id="contentmain">
{$main_content}
</div>
</div>
{/if}
I usually use assign= , so the content blocks, when editing, show up where I want, regardless of the order that they appear in the HTML.

Re: Hiding empty content block -- duplicate block names erro

Posted: Fri Feb 24, 2012 5:43 pm
by Samarama
Thanks so much for quick response! This works perfectly, I'm marking it solved.

Wishbone:
Regardless of your logic, you must only have one content block of a given name. (including {content} without block= )

Thanks for the explanation, this is the part I wouldn't have figured out on my own.