Page 1 of 1

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

Posted: Wed Jan 09, 2013 10:59 am
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.

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

Posted: Wed Jan 09, 2013 2:16 pm
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.

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

Posted: Wed Jan 09, 2013 9:29 pm
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.

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

Posted: Wed Jan 09, 2013 10:25 pm
by calguy1000
One word, one answer: &nbsp;

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

Posted: Thu Jan 10, 2013 12:06 am
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!

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

Posted: Thu Jan 10, 2013 9:16 am
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 "-".

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

Posted: Thu Jan 10, 2013 10:13 am
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.

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

Posted: Thu Jan 10, 2013 10:31 am
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?

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

Posted: Fri Jan 11, 2013 4:22 pm
by ozziejohn
Perfectly clear Paul, and thanks very much for your help!