[solved] Global content blocks no content can't be saved?

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
ozziejohn
Forum Members
Forum Members
Posts: 10
Joined: Mon Jan 07, 2013 9:47 pm

[solved] Global content blocks no content can't be saved?

Post by ozziejohn »

I'm (CMSMS newbie) preparing a new website and want to put Global content blocks on the side. However it seems that if you don't put any content into them, you cannot save them. I just want to put them in the design and prepare them so that an editor can add the content later, but when I want to save these blocks a message drops down from the top saying there is no content. The same happens when I want to delete existing content and save it as empty.

I've seen the code to add which make the blocks invisible if no content is present, but since CMSMS will not accept no content, I can't check to see that my code works.
Last edited by ozziejohn on Fri Jan 11, 2013 4:36 pm, edited 1 time in total.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Global content blocks with no content cannot be saved?

Post by Jo Morg »

I believe you are trying to use GCB's as Custom Content Blocks which are a bit different.
Global Content Blocks MUST have content. The point is to avoid to write the same Smarty code/template block repeatedly. The logic inside it can be whatever you want but not empty. A Custom Content Block is the same as the {content} except that it is customized. The main {content} has to exist on a template but can be empty, and all customized content blocks can also be empty.
Check this and this...
HTH.
"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: Global content blocks with no content cannot be saved?

Post by paulbaker »

I have the same issue. I get round this by setting the GCB to simply "-" when I don't want it to show.

This code in the template shows the GCB but hides it when the GCB is simply "-"

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">
{$UrgentMessageTop}
</div>
{/if}
This code covers both scenarios where the GCB is saved as HTML or plain text.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Global content blocks with no content cannot be saved?

Post by calguy1000 »

One word, one answer: &nbsp;
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.
ozziejohn
Forum Members
Forum Members
Posts: 10
Joined: Mon Jan 07, 2013 9:47 pm

Re: Global content blocks with no content cannot be saved?

Post by ozziejohn »

Hi Paul.
Your code works like a charm ;D although I still have to go and check out the syntax to see what it means...

Thanks!
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Global content blocks with no content cannot be saved?

Post by paulbaker »

Glad to help! Each line of code is:

Comment
Capture the GCB to a variable UrgentMessageTop
If first character is not equal to "-" AND first four characters are not equal to "<p>-" then
...Show DIV with GCB...
End if


@Calguy you mean set the GCB to be hard space? My non-technical clients would find that harder than just typing "-".
ozziejohn
Forum Members
Forum Members
Posts: 10
Joined: Mon Jan 07, 2013 9:47 pm

Re: Global content blocks with no content cannot be saved?

Post by ozziejohn »

Hi Paul.
Coming back to the code.
I understand the first condition, looking to see if "-" is present, but what is the reasoning behind the AND condition.

If you don't want to answer what probably are basic coding questions, don't worry about it. I've now got code that does what I want.

Thanks again Paul.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Global content blocks with no content cannot be saved?

Post by paulbaker »

If you have the HTML tick box checked when editing a GCB, it will (probably) add a <p> paragraph block around the "-" that is entered, so you have to check for that too.

So the "if" code shows the GCB UNLESS it starts with - or <p>-. Not sure if that is any clearer?
ozziejohn
Forum Members
Forum Members
Posts: 10
Joined: Mon Jan 07, 2013 9:47 pm

Re: Global content blocks with no content cannot be saved?

Post by ozziejohn »

Perfectly clear Paul, and thanks very much for your help!
Locked

Return to “CMSMS Core”