-
Notifications
You must be signed in to change notification settings - Fork 15
getPageAssets
This snippet returns a list of images or other assets for the given page (defaults to the current page).
The getPageAssets Snippet accepts the following arguments:
-
&page_id
(integer) Page id of the page whose assets/images you want to see. Defaults to the current page. -
&outerTpl
(string) formats the Outer Wrapper of List (Optional). This can be an inline formatting string or the name of a MODX Chunk. -
&innerTpl
(string) formats the Inner Item of List. This can be an inline formatting string or the name of a MODX Chunk. -
&is_active
(boolean) Get all active records only. Default: 1. -
&is_image
(boolean) if true, return only images, if false, only other assets. If not set, we get everything. Default will return all assets. -
&limit
(integer) Limit the records to be shown (if set to 0, all records will be pulled)
The innerTpl and outerTpl arguments can accept in-line formatting strings or the names of MODX Chunks.
[[getAssets?
&innerTpl=`<img src="[[+asset_id:resize=`300x500`]]" width="300" height="500" alt="[[+Asset.alt]]" />`
]]
The outerTpl should use the [[+content]]
placeholder to indicate where the sum of the innerTpl's will be placed.
[[getAssets?
&innerTpl=`<img src="[[+asset_id:scale2w=`600`]]" width="600" height="[[+asset_id.height]]" alt="[[+Asset.alt]]" />`
&outerTpl=`<div class="myclass">[[+content]]</div>`
]]
Instead of using yet-another-MODX chunk to display a message when no assets are found, you should instead use a MODX "empty" filter to accomplish this:
[[getPageAssets:empty=`No images found`? &innerTpl=`myAssetChunk`]]
Most of the placeholders here should include "Asset." as a prefix.
[[+asset_id]]
[[+Asset.url]]
[[+Asset.thumbnail_url]]
[[+Asset.width]]
[[+Asset.height]]
[[+Asset.alt]]
The getPageAssets Snippet does not force changes to image sizes directly, instead you can use the resize, scale2h, or scale2w output filters to display different sizes.
[[getPageAssets?
&innerTpl=`<li><img src="[[+asset_id:resize=`300x500`]]" width="300" height="500" alt="[[+Asset.alt]]" /></li>`
]]
© 2014 and beyond by Craftsman Coding