[SOLVED] How to check, if global content block is empty
[SOLVED] How to check, if global content block is empty
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.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: How to check, if global content block is empty
{global_content name='myblockname' assign='foo'}
{if $foo == ''}<h3>EMPTY</h3>{else}{$foo}{/if}
{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.
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.
Re: How to check, if global content block is empty
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

Re: How to check, if global content block is 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:urheat wrote:Thanks! The only problem is, that global content block can't be empty
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}
Re: How to check, if global content block is empty
Thanks Paul! My approach was a bit same, though not so goodpaulbaker wrote: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:urheat wrote:Thanks! The only problem is, that global content block can't be empty
So if GCB is not "-" or "<p>-" the block is shown. The "<p>-" is required in case the GCB is set to HTML.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}

Re: [SOLVED] How to check, if global content block is empty
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 *}
{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
My question is, why make a GCB that has nothing in it..?
Re: [SOLVED] How to check, if global content block is empty
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.Dr.CSS wrote:My question is, why make a GCB that has nothing in it..?
Re: [SOLVED] How to check, if global content block is empty
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.paulbaker wrote: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.Dr.CSS wrote:My question is, why make a GCB that has nothing in it..?
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!
* 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!
Re: [SOLVED] How to check, if global content block is empty
Well it's worked well so far. I don't have News implemented for a couple of clients that use this this.Jo Morg wrote:A GCB seems a bit like a recipe for disaster IMO.
One of the many great things about CMSMS is there's almost always more than one way to do things.

Re: [SOLVED] How to check, if global content block is empty
There are situations when it would be good that it could be possible. My question is, why it can't be empty?Dr.CSS wrote:My question is, why make a GCB that has nothing in it..?
Re: [SOLVED] How to check, if global content block is empty
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.
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
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
I understand that page must have a content. But GCB is not a page - it's a part of it.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'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.
