Skip to content
  1. Extras
  2. ms2Gallery
  3. Snippets
  4. ms2Gallery

ms2Gallery

Snippet for outputting a resource gallery.

Parameters

ParameterDefaultDescription
parentsComma-separated list of parent IDs for the query. Default: limited to current parent. Use 0 for no limit.
resourcesComma-separated list of resource IDs to include. If an ID is prefixed with minus, that resource is excluded.
showLogShow extra snippet debug info. Only for authenticated users in mgr context.
toPlaceholderIf set, snippet output is saved to a placeholder with this name instead of printed.
tpltpl.ms2GalleryChunk for the whole gallery using Fenom.
limitMaximum number of results
offsetNumber of results to skip from the start
whereJSON-encoded extra query conditions. For file filtering use table alias File. Example: &where=`{"File.name:LIKE":"%img%"}`
filetypeFile types to include. Use image for images and extensions for others. Example: image, pdf, xls, doc.
showInactiveInclude inactive files.
sortbyrankSort field
sortdirASCSort direction
frontend_css[[+cssUrl]]web/default.cssPath to your CSS, or leave empty and include styles in the site template.
frontend_js[[+jsUrl]]web/default.jsPath to your JS, or leave empty and include scripts in the site template.
tagsComma-separated list of tags for filtering files.
tagsVarIf set, snippet takes tags from $_REQUEST["this_name"]. E.g. tag → filter by $_REQUEST["tag"].
getTagsRun extra queries to get each file's tags as a string?
tagsSeparator,If file tags are requested, they are joined with this string.

Chunks

Before 2.0 ms2Gallery used 4 chunks:

  • tplRow — one result row: tpl.ms2Gallery.row.
  • tplOuter — wrapper: tpl.ms2Gallery.outer.
  • tplEmpty — when no results: tpl.ms2Gallery.empty.
  • tplSingle — when exactly one file: tpl.ms2Gallery.single.

Now there is a single tpl that receives the $files array and must iterate it:

fenom
{if count($files) > 1}
  <!-- multiple files — loop -->
  {foreach $files as $file}
    <a href="{$file.url}">
      <img src="{$file.small}" />
    </a>
  {/foreach}
{elseif count($files) == 1}
  <!-- single image — print full data -->
  {$file | print}
{else}
  No files, show this message.
{/if}

All thumbnails generated for files are available by their aliases.

To keep the old chunk layout, set your old chunks and leave &tpl empty:

modx
[[!ms2Gallery?
  &tplRow=`tpl.ms2Gallery.row`
  &tplOuter=`tpl.ms2Gallery.outer`
  &tplEmpty=`tpl.ms2Gallery.empty`
  &tplSingle=`tpl.ms2Gallery.single`
  &tpl=``
]]

Rewriting to Fenom is recommended for easier use and editing.

Scripts and Styles

frontend_css and frontend_js control which assets are loaded. By default: simple styling and main image change on click (for pre-2.0 chunks).

For the 2.0 chunk, Fotorama is also loaded if the image container has class="fotorama". You can configure it via data attributes.

To disable default scripts and styles, set the parameters to empty:

modx
[[!ms2Gallery?
  &frontend_css=``
  &frontend_js=``
]]

Examples

Output gallery of the current resource:

modx
[[!ms2Gallery]]

Output images from several resources in one gallery:

modx
[[!ms2Gallery?
  &parents=`0`
  &resources=`5,16,7`
]]