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

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.
urheat
Forum Members
Forum Members
Posts: 243
Joined: Sat Oct 17, 2009 6:50 am

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

Post by urheat »

How can I check, if global content block is empty?
Last edited by urheat on Mon Sep 09, 2013 5:08 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post by calguy1000 »

{global_content name='myblockname' assign='foo'}
{if $foo == ''}<h3>EMPTY</h3>{else}{$foo}{/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.
urheat
Forum Members
Forum Members
Posts: 243
Joined: Sat Oct 17, 2009 6:50 am

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

Post 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!
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

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

Post 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.
urheat
Forum Members
Forum Members
Posts: 243
Joined: Sat Oct 17, 2009 6:50 am

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

Post 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.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

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

Post 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 *}
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

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

Post by Dr.CSS »

My question is, why make a GCB that has nothing in it..?
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

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

Post 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.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1973
Joined: Mon Jan 29, 2007 4:47 pm

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

Post 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... ;)
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

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

Post 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
urheat
Forum Members
Forum Members
Posts: 243
Joined: Sat Oct 17, 2009 6:50 am

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

Post 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?
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

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

Post 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.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

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

Post 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..?
urheat
Forum Members
Forum Members
Posts: 243
Joined: Sat Oct 17, 2009 6:50 am

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

Post 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.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

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

Post by paulbaker »

@urheat :D
Locked

Return to “CMSMS Core”