Page 1 of 1

[SOLVED] Show Content-Block and additional HTML only if block contains data?

Posted: Fri Oct 26, 2007 8:41 pm
by nhaack
Hi there,

due to the help of the forum (mainly by reading), I could already get down the road pretty far. The technical issues are nearly all solved, so I am beginning to re-do everything the clean way and bring the templates to live. Thanks again for the indirect support and answers to my questions.

But now I got stuck again.

For the article template, I'd like to post up to 3 optional links. The specific page template contains 6 fields. 3 for the URLs and 3 descriptions. I implement the links in the template like this:

Code: Select all

...
   <li class="article_links_item">
	<a href="http://{content block="exturl2" oneline="true"}">{content block="exturl2_desc" oneline="true"}</a>
   </li>
...
But if no content would be provided, I also want the sourrounding HTML to be hidden as well. I wondered wether there is a solution which doesn't require a user tag or something like this. I am not much of a coder and I already spent hours of searching. Probably I took the wrong word for the query (then please give me hint).

I tried something like this:

Code: Select all

...
    {capture assign="url2"}  {content block="exturl2"}  {/capture}

    {if isset($url2)}

  ...html...

    {/if}
...
But that didn't work as it still shows the. As far as I understood by now, I check if a variable exists, but  the variable is created even when the element is empty (I hoped it would work). I already spent hours on searching and reading but couldn't get any closer.

If you could point me to the right direction or coincidentaly have a solution at hand, I would be very thankfull:)

best regards
nils

Re: Show Content-Block and additional HTML only if block contains data?

Posted: Fri Oct 26, 2007 8:45 pm
by calguy1000
{content block='url2' assign='url2' oneline='true'}
{if !empty($url2)}
  {content block='text2'}
{/if}

Re: Show Content-Block and additional HTML only if block contains data?

Posted: Sat Oct 27, 2007 4:05 pm
by nhaack
Hey calguy1000,

that works great! Thank you very much! As I only have little spare time on my hands for this private project, you saved me a lot of time as I can now concentrate on the further implementation! Thanks a lot  :)!

regards
nils

Re: [SOLVED] Show Content-Block and additional HTML only if block contains data?

Posted: Tue Mar 11, 2008 3:27 pm
by nicmare
thank you very much. i had exactly the same problem. couldn't find the solution in doc from cmsms and smarty. d'oh

Re: [SOLVED] Show Content-Block and additional HTML only if block contains data?

Posted: Mon Apr 07, 2008 2:38 pm
by Maticomp
Is it possible to do the same, but checking whether the block exists, and not whether it is empty? If it doesn't exist, the captured variable always contains data with smarty error telling me there is no such block. I am trying to show content_block of name $page_alias, to provide additional content related to particular pages. But without creating empty blocks what I can get is only smarty error at the sidebar.

Any help would be very appreciated,

Thanks!
M.