Skip to content
Everett Griffiths edited this page Jul 8, 2014 · 5 revisions

Asset

Returns HTML representing a single asset, usually an image tag or a download link.

Parameters

The Asset Snippet accepts the following arguments:

  • &asset_id (integer) Unique asset id of the asset you would like to display.
  • &width (integer) in pixels (optional)
  • &height (integer) in pixels (optional)
  • &tpl (string) either a MODX chunk or a formatting string

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 does may distort the image!

Examples

Image Tag

[[Asset? &asset_id=`123` 
    &tpl=`<img src="[[+url]]"/>` 
    &height=`100` 
    &width=`100` 
]]

Download Link

[[Asset? &asset_id=`123` 
    &tpl=`<a href="[[+url]]"/>Download</a>` 
]]

Moxycart Examples

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]]"/>`  
]]
Clone this wiki locally