Resolve Matrix Asset ID

This utility is only available for Components at Edge. The use of this function requires session based auth enabled for the Content Management Content API.

The resolveMatrixAssetById function accepts an asset ID 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 IDs is using the context asset ID utility - Context asset ID.

// A simple "Page Header" component.
export default {
  async main({}, info) {
    const currentPageAssetId = info.ctx.assetId; (1)
    const data = info.fns.resolveMatrixAssetById(currentPageAssetId, [`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.