Resolve Matrix Asset URL
This utility is only available for Components at Edge. The use of this function requires session based auth enabled for the Squiz Content Management Content API. |
The resolveMatrixAssetByUrl
function accepts a URL and resolves the asset data by making a request to the configured Content Management system.
How to use it
The recommend source for Content Management asset URLs is using the context URL utility - Context URL.
// A simple "Page Header" component.
export default {
async main({}, info) {
const currentUrl = info.ctx.url; (1)
const data = info.fns.resolveMatrixAssetByURL(currentUrl, [`metadata`, `thumbnail`]); (2)
return ` (3)
<div class="banner">
<img src="${data.thumbnail.url}" alt="${data.thumbnail.alt}" />
<h1>${data.name}</h1>
<p>
${data.metadata.description}
</p>
</div>
`;
}
}
1 | Get the assetId from the context object. |
2 | Retrieve asset data from Content Management system. |
3 | Print a banner using the returned asset data. |