-
Notifications
You must be signed in to change notification settings - Fork 15
Asset
fireproofsocks edited this page Nov 4, 2014
·
5 revisions
Fetches an asset by its id and formats its properties as HTML, usually an image tag or a download link. Think of this Snippet as the solution to "I need an image tag and/or download link of asset X".
The Asset Snippet accepts the following arguments:
-
&asset_id
(integer) Unique asset id of the asset you would like to display. (required) -
&width
(integer) in pixels (optional) -
&height
(integer) in pixels (optional) -
&tpl
(string) either a MODX chunk or a formatting string. Default value is<img src="[[+url]]" width="[[+width]]" height="[[+height]]" alt="[[+alt]]" />
Note the following behavior when specifying the desired size:
- If no &height or &width arguments are passed, then the full size of the original asset will be returned.
- If the snippet call sets a &width but no &height, then the result will be scaled to the desired width.
- If the snippet call sets a &height but no &width, then the result will be scaled to the desired height.
- If both &height and &width are set, scale to the desired dimensions. This may distort the image: it's up to you to preserve the aspect ratio.
If you supply &height
and &width
, you will force a resized image thumbnail to be generated.
[[Asset? &asset_id=`123`
&tpl=`<img src="[[+url]]"/>`
&height=`100`
&width=`100`
]]
If you need to get the asset's original size, then omit the height and width.
[[Asset? &asset_id=`123`]]
[[Asset? &asset_id=`123`
&tpl=`<a href="[[+url]]"/>Download</a>`
]]
If you are using this with Moxycart, then you will often be passing in the asset_id as a parameter, e.g. for your primary image (at its original dimensions):
[[Asset? &asset_id=`[[+asset_id]]`
&tpl=`<img src="[[+url]]"/>`
]]
Or as a custom image field:
[[Asset? &asset_id=`[[+my_custom_image_field]]`
&tpl=`<img src="[[+url]]"/>`
]]
© 2014 and beyond by Craftsman Coding