How do I access a chooser field's chosen asset?

Cascade API

When working with the Cascade API and choosers, there is an asset property which will be set to the chosen asset's API Object if an asset is chosen, or null if no asset is chosen.

Because the asset property will be null if no asset is chosen , it is advised to ensure an asset is chosen before attempting to access it's properties.

Consider the following example:

#set ($thumbnailImage = $currentPage.getStructuredDataNode("thumbnail-image")) 
#if (!$_PropertyTool.isNull($thumbnailImage.asset))
    <img src="${}" />

Index Block and XPath Tool

When working with Index Blocks and choosers, the chooser field will contain a number of XML elements which provide information about the given asset, such as: name, path, link, site, etc. If no asset is chosen, a path of / will be present and no additional XML elements.

Much like accessing chosen assets using the Cascade API, it is advised to first check if an asset is chosen before attempting to access more information about the chosen asset.

Consider the following example:

#set ($thumbnailImage = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/thumbnail-image[path != '/']"))
#if ($thumbnailImage.size() > 0)
    <img src="${thumbnailImage.getChild("link").value}" />

Not seeing the contents of the chosen asset?

If you need to access the rendered content of the chosen asset, see this article.