Back

Image gallery that works with file assets and documents

Description

The default version of image-gallery.vtl that comes with dotCMS only works with image files of type Document.  If a folder contains image files of type File Asset they won't get picked up.  With this revised version, image files can be of either type.

Also it sorts by filename instead of last update date.

Code

#set($_qk = "+(structureName:Document structureName:FileAsset) +confolder:$!{folder1} +(Document.metaData.contentType:image/* FileAsset.metaData.contentType:image/*)")
#set($cons = $dotcontent.pull(${_qk},$!{numberOfResults},""))

#if ($UtilMethods.isSet($title))
  <h3>$!{title}</h3>
#end
#if($cons.size() > 0)
	<ul class="photo-gallery">
		#foreach($con in $sorter.sort($cons, "fileName"))
			<li>
				<a class="prettyPhoto" href="/contentAsset/resize-image/$con.identifier/fileAsset" rel="prettyPhoto[x]" title="$!{con.title}" style="background: url(/contentAsset/resize-image/$con.identifier/fileAsset/h/65) no-repeat center center;">
					$!{con.title}
				</a>
			</li>
		#end
	</ul>
#else
	There are currently no images in the folder.
#end

<div class="clear p4"></div>