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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
nhaack

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

Post 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
Last edited by nhaack on Sat Oct 27, 2007 4:06 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post by calguy1000 »

{content block='url2' assign='url2' oneline='true'}
{if !empty($url2)}
  {content block='text2'}
{/if}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nhaack

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

Post 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
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

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

Post 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
Maticomp
Forum Members
Forum Members
Posts: 12
Joined: Mon Oct 17, 2005 6:26 pm

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

Post 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.
Locked

Return to “CMSMS Core”