Page 1 of 1

[SOLVED] Making Images Appear When Selected in ListIt2 Mod

Posted: Fri Feb 21, 2014 3:31 pm
by govicinity
CMSMS 1.11.10
AdvancedContent 0.9.4.3
CGExtensions 1.38.1
CGSimpleSmarty 1.7.1
CGSmartImage 1.15
ListIt2 1.4.1
ListIt2Projects 1.4.1

I am currently using ListIt2 For a nice little plug in (ListIt2Projects 1.4.1), I have an image I want to rotate on the ListIt2 projects pages that are created, this works really well, but I would like to only have as many images as selected in the file dropdown in the ListIt2 admin area in the backend showing on the frontend when you are setting the "project" item up, there are three available options for images, but if only two are selected (I don't want to make three images mandatory) I only want to have two images rotating.

So I am using the {if} value to ignore the unselected image option.

Code: Select all

<ul class="slides">
<li><img src="{root_url}/uploads/images/Projects/{$item->fielddefs.main_image.value}" alt="{$item->fielddefs.main_image.value}" /></li>
{html_image file="{root_url}/uploads/images/Projects/{$item->fielddefs.secondary_image_1.value}" alt="{$item->fielddefs.secondary_image_1.value}" assign="secondary_image_1"}
{if !empty($secondary_image_1)}
<li>{$secondary_image_1}</li>
{/if}
{html_image file="{root_url}/uploads/images/Projects/{$item->fielddefs.secondary_image_2.value}" alt="{$item->fielddefs.secondary_image_2.value}" assign="secondary_image_2"}
{if !empty($secondary_image_2)}
<li>{$secondary_image_2}</li>
{/if}
</ul>
I hope I've explained that OK! I have used the html_image smarty, not sure if this works in CMSMS though, it makes sense it would, but it doesn't seem to (or I'm not doing it right!).

The first <li> image item works wonderfully, but the subsequent two with the {if} values don't. Any help very appreciated indeed.

Re: Making Images Appear When Selected in ListIt2 Module

Posted: Fri Feb 21, 2014 3:47 pm
by velden
I think it's not efficient to do stuff with a variable, and then afterwards check if something happened and disregard it if not.

Start to just check what is the output of
{$item->fielddefs.secondary_image_1.value} and
{$item->fielddefs.secondary_image_2.value}.

Use that in your if statements.

NOT tested:

Code: Select all

<ul class="slides">
<li><img src="{uploads_url}/images/Projects/{$item->fielddefs.main_image.value}" alt="{$item->fielddefs.main_image.value}" /></li>

{if $item->fielddefs.secondary_image_1.value != ''}
<li><img src="{uploads_url}/images/Projects/{$item->fielddefs.secondary_image_1.value}" alt="" /></li>
{/if}

{if $item->fielddefs.secondary_image_2.value != ''}
<li><img src="{uploads_url}/images/Projects/{$item->fielddefs.secondary_image_2.value}" alt="" /></li>
{/if}
</ul>
ps. I replaced '{root_url}/uploads' with '{uploads_url}' (personal preference)

Re: Making Images Appear When Selected in ListIt2 Module

Posted: Fri Feb 21, 2014 4:50 pm
by Stikki

Code: Select all

{* Init images based on field type (assuming all GBFilePicker type fields are images)
****************************************************************************************}

{foreach from=$item->fielddefs item=field}
	{if $field->GetType() == 'GBFilePicker' && $field->HasValue()}
		{append var='product_images' value=$field->GetValue()}
	{/if}
{/foreach}

{* Output images
****************************************************************************************}

<ul>
{foreach from=$product_images item=image}									
	<li>{CGSmartImage src1='uploads' src2=$image alt=$item->title noembed=1}</li>
{/foreach}
</ul>

Re: Making Images Appear When Selected in ListIt2 Module

Posted: Wed Feb 26, 2014 4:25 pm
by govicinity
@Velden, thanks for your reply, I have just added your solution to the site, it works wonderfully, so thanks for taking the time to give me a hand, here is what we used:

Code: Select all

<ul class="slides">
<li><img src="{uploads_url}/images/Projects/{$item->fielddefs.main_image.value}" alt="{$item->fielddefs.main_image.value}" /></li>
{if $item->fielddefs.secondary_image_1.value != ''}
<li><img src="{uploads_url}/images/Projects/{$item->fielddefs.secondary_image_1.value}" alt="" /></li>
{/if}
{if $item->fielddefs.secondary_image_2.value != ''}
<li><img src="{uploads_url}/images/Projects/{$item->fielddefs.secondary_image_2.value}" alt="" /></li>
{/if}
</ul>
Can I ask the difference between {root_url} and {uploads_url}, I've not seen the uploads smarty used before.

Thanks @Stikki for your solution as well, I'll certainly give that a try in the future.