Page 1 of 1

[SOLVED] Templates For Global Content Block?

Posted: Thu May 05, 2011 11:31 am
by laits
Hi all,

Sometimes I over think things when it comes to cms, but I woner if anyone can give me a solution to my problem.

I have an area of content, that is repeated on every page, but would like it to be easily content managed for the client. The area consists of 3 boxes, which i'd like to divide into Title, Sub-title & Content.

If I put it in a global content block, then individual areas become surrounded by my code, with the possibility of the client breaking it, this is what is so good about page templates, they can only enter the text, and the template styles this.

Is there a way of assigning a template to a GCB, or even assigning a page to a GCB so that the client can enter various info into something that appears on every page?

I could repeat the content blocks for every page, but that would be ridiculous as the client would have to update every page with the same small changes.

Does anyone know what I'm getting at? Is there a Solution/Module? Currently I'm playing with GCB within GCB's which isn't turning out very elegant at all.

Rich

Re: Templates For Global Content Block?

Posted: Fri May 06, 2011 2:05 pm
by stevew
Maybe you could put something like this in your page template:

Code: Select all

          {capture assign="special_title"}{content block="special_title"}{/capture}
          {if $special_title != ''}
            <div class="special_title">{$special_title}</div>
          {/if}
          {capture assign="special_subtitle"}{content block="special_subtitle"}{/capture}
          {if $special_subtitle != ''}
            <div class="special_subtitle">{$special_subtitle}</div>
          {/if}
          {capture assign="special_content"}{content block="special_content"}{/capture}
          {if $special_content != ''}
            <div class="special_content">{$special_content}</div>
          {/if}
Now, whenever a user creates a new page, there is a text area for entering the text of title, subtitle and content. These blocks will only show up on the page if there is content in them. Check out the Help for the {content} tag for more info and to see the parameters you can use (e.g. oneline=true for title and subtitle).

Their position on the page will depend on where in the template you put the code. And then you will need to use CSS to style the DIVs.

This is a recipe from the excellent book by Samuel Goldstein, CMS Made Simple Development Cookbook (Packt Publishing) http://www.packtpub.com/cms-made-simple ... kbook/book. Very highly recommended!

Re: Templates For Global Content Block?

Posted: Fri May 06, 2011 2:26 pm
by uniqu3
@stevew, laits actually talked about GCB not Content block ;)

@laits i wouldn't know of a nice way but creating 3 GCB's one for title, subtitle, content which again would be ridiculous to edit.

There would be another way with using CGSimple smarty module.

For example create new page called "Global Content", hide it from menu and set it to inactive.
Create new Template, it can be completely blank containing only {content} as it's required or you will not be able to edit content.

This template could look like this:

Code: Select all

{content assign="mycontent" label="Hey i can enter content here"}
<!-- the title -->
{content block="mytitle" label="Insert your big fat title here:"}
<!-- the subtitle -->
{content block="mysubtitle" label="My tiny subtitle goes here:}
<!-- the content -->
{$mycontent}
Now in your main page template you could do following:

Code: Select all

<!-- get mytitle -->
{capture assign='thetitle'}{$cgsimple->get_page_content('global-content','mytitle')}{/capture}
<!-- thesubtitle -->
{capture assign='thesubtitle'}{$cgsimple->get_page_content('global-content','mysubtitle')}{/capture}
<!-- thecontent -->
{capture assign='thecontent'}{$cgsimple->get_page_content('global-content','mycontent')}{/capture}

<!-- now show my big fat title -->
{if !empty($thetitle)}
    <h2>{$thetitle}</h2>{/if}
       <!-- and my subtitle -->
      {if !empty($thesubtitle)}
         <span class="subtitle">{$thesubtitle}</span>{/if}
         <!-- and finaly content -->
         {if !empty($thecontent)}
         <div class="mynicecontent">
           {$thecontent}
         </div>{/if}
<!-- and the end -->
           
I didn't test it if it works, if it doesn't check for typos ;)

Re: Templates For Global Content Block?

Posted: Fri May 06, 2011 2:34 pm
by stevew
@uniq3 You're right :-) but laits says "I have an area of content, that is repeated on every page, but would like it to be easily content managed for the client. The area consists of 3 boxes", so it would be quite possible to handle this using content blocks. That would certainly be easy for the client to manage and there'd be no danger of messing up any code.

But maybe you're right that there's an advantage in using a global content block, I don't know.

Re: Templates For Global Content Block?

Posted: Fri May 06, 2011 2:39 pm
by uniqu3
@stevew now when i read it again, i see it :) so yes your answer is ideal if he needs to change that content on each page.

Sorry ;)

Re: Templates For Global Content Block?

Posted: Fri May 06, 2011 3:13 pm
by laits
Thanks Guys...

Actually it was probably my fault for not explaining myself more clearly.

I'm going to test both, and see what they do - it can't harm to learn both methods, and both methods have got to better than my multiple GCB's inside a GCB.

@stevew - Good shout on the book, it's on my Ipad now, something to read on the train.

@uniq3 - I've subscribed to the RSS on your blog, some nice stuff on there :-)

Thanks again guys!

Re: [SOLVED] Templates For Global Content Block?

Posted: Fri May 06, 2011 3:29 pm
by uniqu3
@book
dang i still wait at my print copy, for some reason i am not eBook reader. Old-fashioned ;D