[SOLVED] Making Images Appear When Selected in ListIt2 Mod

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
govicinity
Forum Members
Forum Members
Posts: 125
Joined: Tue Nov 22, 2011 2:22 pm

[SOLVED] Making Images Appear When Selected in ListIt2 Mod

Post 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.
Last edited by govicinity on Wed Feb 26, 2014 4:26 pm, edited 1 time in total.
Going up, woop, woop.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Making Images Appear When Selected in ListIt2 Module

Post 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)
Stikki

Re: Making Images Appear When Selected in ListIt2 Module

Post 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>
govicinity
Forum Members
Forum Members
Posts: 125
Joined: Tue Nov 22, 2011 2:22 pm

Re: Making Images Appear When Selected in ListIt2 Module

Post 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.
Going up, woop, woop.
Post Reply

Return to “Modules/Add-Ons”