Page 1 of 1

[SOLVED] Variable in content_image parameter

Posted: Tue Jan 28, 2014 12:50 pm
by chillifish
Looking at the below, it should be pretty obvious what I'm trying to do.

Code: Select all

{content_image block='Image 1' width='490' height='300' dir='/frogmore/pics/galleries/$page_alias'}
I've tried putting the $page_alias variable in double quotes, single quotes, backticks. Is what I'm trying to do even possible?

Re: Variable in content_image parameter

Posted: Tue Jan 28, 2014 1:22 pm
by HarmO
I'm afraid the admin editor does not look at the $page_alias variable the same way as the fronted template does.

BTW: What you try to do would give an error when you create a new page since the page alias is not yet defined at that moment...

Re: Variable in content_image parameter

Posted: Tue Jan 28, 2014 3:05 pm
by chillifish
Doh, of course. explains why I'm unable to do it via a UDT as shown below:

Code: Select all

// Use page_alias parameter to define image path
$image_path = "/frogmore/pics/galleries/".$params['page_alias']."/";

// Get image number from paramater
$image_no = "Image ".$params['image_no'];

// Write the smarty
$smarty_data = "{content_image block='".$image_no."' width='490' height='300' dir='".$image_path."'}";
$smarty->display("eval:".$smarty_data);

echo "testing ".$image_path;
I'll have to think of something else.

Re: Variable in content_image parameter

Posted: Tue Jan 28, 2014 3:16 pm
by velden
What are you trying to do?

Maybe we can think of another approach if we know.

Re: Variable in content_image parameter

Posted: Tue Jan 28, 2014 3:37 pm
by calguy1000

Code: Select all

{content_image block='Image 1' width='490' height='300' dir='/frogmore/pics/galleries/$page_alias'}
Two reasons why this won't work:
a: the page alias is not available in a smarty variable in the editcontent form at all...
b: single quotes are absolute strings.

Re: Variable in content_image parameter

Posted: Wed Jan 29, 2014 3:42 pm
by chillifish
I wanted a an image rotator on each page. I had a script that rotated four images. The plan was that a content editor would be taken to a different folder depending on what page they were editing and could simply select from a dropdown what images they wanted. I've now decided to use another content block that they can put four images in, it means the file browser can be used instead. It's not quite as simple to use, but the content editor is relatively savvy.

Re: Variable in content_image parameter

Posted: Thu Jan 30, 2014 7:40 am
by velden
Let me post some code I use on one site which adds a tab 'Vier fotos' to the 'edit content' page, let the editor select 4 images (user friendly).
In this example the images are only displayed if all 4 images are selected.

It uses modules: GBFilePicker and CGSmartImage

Code: Select all

{content_module block="filepicker_block_1" module="GBFilePicker" assign="image1" label="Optioneel: afbeelding 1 in rij van 4" mode="browser" media_type="image" dir="images" tab="Vier fotos"}
{content_module block="filepicker_block_2" module="GBFilePicker" assign="image2" label="Optioneel: afbeelding 2 in rij van 4" mode="browser" media_type="image" dir="images" tab="Vier fotos"}
{content_module block="filepicker_block_3" module="GBFilePicker" assign="image3" label="Optioneel: afbeelding 3 in rij van 4" mode="browser" media_type="image" dir="images" tab="Vier fotos"}
{content_module block="filepicker_block_4" module="GBFilePicker" assign="image4" label="Optioneel: afbeelding 4 in rij van 4" mode="browser" media_type="image" dir="images" tab="Vier fotos"}

{if $image1 && $image2 && $image3 && $image4}
   <div class="image-block shadow-box">
     {CGSmartImage src=$image1 filter_croptofit='125,125,,1' noembed=1 alt=""}
     {CGSmartImage src=$image2 filter_croptofit='125,125,,1' noembed=1 alt=""}
     {CGSmartImage src=$image3 filter_croptofit='125,125,,1' noembed=1 alt=""}
     {CGSmartImage src=$image4 filter_croptofit='125,125,,1' noembed=1 alt=""}
   </div>
{/if}
Admin: Edit Content
4images_be_result.jpg
4images_be_browse.jpg
Front end result:
4images_fe_result.jpg

Re: Variable in content_image parameter

Posted: Fri Jan 31, 2014 10:20 am
by chillifish
That's a great help, thanks very much.