Page 1 of 2

[SOLVED] How to check, if global content block is empty

Posted: Mon Sep 09, 2013 3:22 pm
by urheat
How can I check, if global content block is empty?

Re: How to check, if global content block is empty

Posted: Mon Sep 09, 2013 3:25 pm
by calguy1000
{global_content name='myblockname' assign='foo'}
{if $foo == ''}<h3>EMPTY</h3>{else}{$foo}{/if}

Re: How to check, if global content block is empty

Posted: Mon Sep 09, 2013 5:07 pm
by urheat
calguy1000 wrote:{global_content name='myblockname' assign='foo'}
{if $foo == ''}<h3>EMPTY</h3>{else}{$foo}{/if}

Thanks! The only problem is, that global content block can't be empty ;) But I'll manage now - thanks!

Re: How to check, if global content block is empty

Posted: Tue Sep 10, 2013 3:42 pm
by paulbaker
urheat wrote:Thanks! The only problem is, that global content block can't be empty ;)
Yeah, I get clients to put a "-" in the global content block if they don't want it to show. Then my template is something like:

Code: Select all

{* Show UrgentMessageTop if required *}
{capture assign='UrgentMessageTop'}{global_content name='UrgentMessageTop'}{/capture}
{if $UrgentMessageTop|substr:0:1 ne '-' AND $UrgentMessageTop|substr:0:4 ne '<p>-'}
<div id="UrgentMessageTop">
<div class="UrgentText">
{$UrgentMessageTop}
</div>
</div>
{/if}
So if GCB is not "-" or "<p>-" the block is shown. The "<p>-" is required in case the GCB is set to HTML.

Re: How to check, if global content block is empty

Posted: Wed Sep 11, 2013 11:14 am
by urheat
paulbaker wrote:
urheat wrote:Thanks! The only problem is, that global content block can't be empty ;)
Yeah, I get clients to put a "-" in the global content block if they don't want it to show. Then my template is something like:

Code: Select all

{* Show UrgentMessageTop if required *}
{capture assign='UrgentMessageTop'}{global_content name='UrgentMessageTop'}{/capture}
{if $UrgentMessageTop|substr:0:1 ne '-' AND $UrgentMessageTop|substr:0:4 ne '<p>-'}
<div id="UrgentMessageTop">
<div class="UrgentText">
{$UrgentMessageTop}
</div>
</div>
{/if}
So if GCB is not "-" or "<p>-" the block is shown. The "<p>-" is required in case the GCB is set to HTML.
Thanks Paul! My approach was a bit same, though not so good ;) But why Global Content Block can't be empty? I think, it would be the best case, if it could.

Re: [SOLVED] How to check, if global content block is empty

Posted: Thu Sep 12, 2013 12:46 pm
by psy
I use {global_content name=myblock assign=x}
{if $x|strip_tags|strip != ''}{$x}{/if}

This gets rid of any rogue paragraph tags. In the gcb, I put a smarty comment, eg {* move along folks, nothing to see here *}

Re: [SOLVED] How to check, if global content block is empty

Posted: Wed Sep 25, 2013 6:14 pm
by Dr.CSS
My question is, why make a GCB that has nothing in it..?

Re: [SOLVED] How to check, if global content block is empty

Posted: Thu Sep 26, 2013 10:15 am
by paulbaker
Dr.CSS wrote:My question is, why make a GCB that has nothing in it..?
I set up a GCB for "emergency info" e.g. site is closed due to adverse weather. Most of the time the GCB is empty (no emergency). Site administrator has access to edit the GCB. When it has text in it, the GCB is shown wrapped in a DIV with warning triangle, red border etc. at the top of each page of the website.

Re: [SOLVED] How to check, if global content block is empty

Posted: Thu Sep 26, 2013 12:00 pm
by Jo Morg
paulbaker wrote:
Dr.CSS wrote:My question is, why make a GCB that has nothing in it..?
I set up a GCB for "emergency info" e.g. site is closed due to adverse weather. Most of the time the GCB is empty (no emergency). Site administrator has access to edit the GCB. When it has text in it, the GCB is shown wrapped in a DIV with warning triangle, red border etc. at the top of each page of the website.
I'd use a News Category for that, which gives me the added ability of having automatic timed messages, if needed. A GCB seems a bit like a recipe for disaster IMO.
My two cents... ;)

Re: [SOLVED] How to check, if global content block is empty

Posted: Thu Sep 26, 2013 4:36 pm
by paulbaker
Jo Morg wrote:A GCB seems a bit like a recipe for disaster IMO.
Well it's worked well so far. I don't have News implemented for a couple of clients that use this this.

One of the many great things about CMSMS is there's almost always more than one way to do things. ;D

Re: [SOLVED] How to check, if global content block is empty

Posted: Sun Sep 29, 2013 3:13 pm
by urheat
Dr.CSS wrote:My question is, why make a GCB that has nothing in it..?
There are situations when it would be good that it could be possible. My question is, why it can't be empty?

Re: [SOLVED] How to check, if global content block is empty

Posted: Sun Sep 29, 2013 9:54 pm
by psy
I use the 'strip_tags|strip' to test for empty WYSIWYG textareas in content blocks rather than GCBs, eg if I create a content block for a sidebar and the user enters something in it, then the page will appear as 2 columns.

When the content block is empty (even with empty paragraph tags and/or smarty comments), the page will default to one column, full width by assigning relevant CSS classes etc in the template according to the result of the test.

I know there are ways to use checkboxes etc with extra modules, but this makes it a no-brainer for the user and no custom module overhead.

Re: [SOLVED] How to check, if global content block is empty

Posted: Tue Oct 15, 2013 7:25 pm
by Dr.CSS
Just like the {content} tag in a page template, if you make a page but don't put anything in the Content: block it will give the "No Content added" warning, the logic is why make a page with nothing in it as in would you have a visitor look at a page with nothing in it so why make a GCB with nothing in it..?

Re: [SOLVED] How to check, if global content block is empty

Posted: Wed Oct 16, 2013 10:52 am
by urheat
Dr.CSS wrote:why make a page with nothing in it as in would you have a visitor look at a page with nothing in it so why make a GCB with nothing in it..?
I understand that page must have a content. But GCB is not a page - it's a part of it.

I'll give you an example why I would prefer the fact that GCB could be empty.

I made a website for a hotel. Sometimes, for example in specific seasons, they have some extra offers and so on. This offer is one GCB that is shown in front page if it is not empty. Of course I could make this using news, but I think that it is easier for editor to understand UI when "news are news". Using GCBs they can update for example footer and this offer area. For editors GCBs are easy to use.

I think that there really isn't a reason why GCBs can't be empty. I highly respect the developers of CMSMS, but maybe there are situations that some restrictions are just unnecessary.

What Paul previously said, is exactly how I feel also:"One of the many great things about CMSMS is there's almost always more than one way to do things. ;D". I rest my case for now.

Re: [SOLVED] How to check, if global content block is empty

Posted: Wed Oct 16, 2013 11:09 am
by paulbaker
@urheat :D