CMS Made Simple Forums
https://forum.cmsmadesimple.org/

Using variables with global content blocks
https://forum.cmsmadesimple.org/viewtopic.php?f=20&t=47491
Page 1 of 1

Author:  oneilldesign [ Mon Sep 20, 2010 10:51 am ]
Post subject:  Using variables with global content blocks

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:

\$1:
<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).

Author:  uniqu3 [ Mon Sep 20, 2010 11:17 am ]
Post subject:  Re: Using variables with global content blocks

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):
\$1:

    {foreach from=$images item=image}
    {if $image->isdir}
  • {$image->titlename}{$image->comment}

  • {else}
  • {$image->titlename}{$image->comment}

  • {/if}

{/foreach}


As second adding something like this in your template (Layout -> Templates -> Your Template):
\$1:
{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.
\$1:
{Gallery dir=$page_alias template='yourtemplate'}


There are probably more options, but this is what first came up in my mind.

Author:  oneilldesign [ Tue Sep 21, 2010 9:02 am ]
Post subject:  Re: Using variables with global content blocks

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.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/