Page 1 of 1

Fudging multi-image upload with GBFilePicker and ListIt2

Posted: Thu Jun 26, 2014 8:38 am
by psy
By default, the LI2 field definition type GBFilePicker only allows you select one image BUT, if you don't delete the previous image AND each pic has a different name, the image files remain in the directory.

Here's what I did...

1. Create a GBFilePicker field definition in my custom LI2 instance
2. Uploaded a number of images
3. Selected one of the images from the dropdown in the admin LI2 item edit area. This saves the image path.

Then in the template put:

Code: Select all

	{assign var='path' value='uploads/images/press/'|cat:$item->item_id|cat:'/*.*'}	
	{assign var='images' value=$path|glob}
	
	<div class="gallery">
		<ul class="clearing-thumbs" data-clearing>
			{foreach from=$images item=image}
				<li><a href="{$image|escape:'url'|replace:'%2F':'/'}"><img src="{CGSmartImage src=$image|escape:'url'|replace:'%2F':'/' notag=1 width=200}" data-caption="{$item->title}"></a></li>
			{/foreach}
		</ul>
	</div>
What this does is collect all the images in the directory associated with the item id and, in this case with CGSmartImage, outputs the thumbnails.

You could get clever and create a module_custom template to show all the thumbnails in the admin item edit screen but didn't need it so didn't go there.

Have fun with it.