Using variables with global content blocks

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
oneilldesign
New Member
New Member
Posts: 7
Joined: Mon Sep 20, 2010 10:28 am

Using variables with global content blocks

Post by oneilldesign »

I'm using the latest version of CMSMS (first time user) and would appreciate any advice on using variables to choose whether to display an image on a per-page basis.

For example, I have created a global content block which displays an image carousel. I've used {$page_alias} within the GCB to automatically choose the three images based on the current page alias. Then on the relevant page, I've inserted the GCB and it is correctly displaying the images in the carousel.

So, my questions are:

1. Is there a way to include this GCB on all pages (i.e. in the Template rather than each Page) but only have the carousel display if the image files are found?

2. The image carousel includes a caption which is currently hard-coded, but these captions also need to change per-page/per-image. Ideally these captions would somehow come from variables in the Page content. Is there a way to do this?

3. How would it automatically display as many images as required? Am I better off creating subfolders for each section, named using the page alias, and then using PHP to get a folder listing?

The carousel code is as follows:

Code: Select all

<ul id="sliderContent">
<li class="sliderImage"><img src="template/images/sections/{$page_alias}-01.jpg" alt="No job is too big or too small" width="430" height="250" /><span class="top">No job is too big or too small</span> </li>
<li class="sliderImage"><img src="template/images/sections/{$page_alias}-02.jpg" alt="Outstanding warehouse facilities" width="430" height="250" /> <span class="top">Outstanding facilities</span></li>
</ul>
I realise this is probably a complex request but being a CMSMS novice, I'm not really sure of the full capabilities of the system (and have read the Wiki and forum topics, and looked at possible modules that could handle all of this).
uniqu3

Re: Using variables with global content blocks

Post by uniqu3 »

Hi and welcome.

1. yes you are able to place GCBs in Template.
2. personally i would prefer using a module like Gallery for task you want to achieve.

For example using Gallery you would create new Gallery Template (Content -> Gallery -> Templates) using your code (not tested but you will get the point):

{foreach from=$images item=image}
{if $image->isdir}
thumb}" alt="{$image->titlename}" />{$image->comment}
{else}
file}" alt="{$image->titlename}" />{$image->comment}
{/if}

{/foreach}
As second adding something like this in your template (Layout -> Templates -> Your Template):
{capture assign='galdir'}{content block='Gallery' oneline='true'}{/capture} {*gives you input field on each page to enter gallery directory name, we capture this so we can use dir option in Gallery*}
{if !empty($galdir)}{Gallery template='nameofyourcustomtemplate' dir=$galdir}{/if}
{*this is placed where your slide should be displayed, if in edit page Gallery directory name is entered it will be displayed on the page*}
Another option would be this, but you would need a gallery for each page alias.
{Gallery dir=$page_alias template='yourtemplate'}
There are probably more options, but this is what first came up in my mind.
Last edited by uniqu3 on Mon Sep 20, 2010 11:32 am, edited 1 time in total.
oneilldesign
New Member
New Member
Posts: 7
Joined: Mon Sep 20, 2010 10:28 am

Re: Using variables with global content blocks

Post by oneilldesign »

Thanks for the reply. I'll look at how I can go about doing it, but I think in order to finish the project I may end up simply inserting the content onto each relevant page. Chances are the client will never update the site anyway.

But you've given me some great ideas, so thanks again.
Post Reply

Return to “Layout and Design (CSS & HTML)”