Context asset ID

This utility is only available for Components at Edge.

When a component has been added to a Squiz Content Management page, it is possible to retrieve the parent asset ID from the context object.

This is useful when making requests to Squiz Content Management using the asset ID for additional data and content.

Usage

The recommended method for retrieving additional data using the asset ID is the resolveMatrixAssetById utility. For more information read Resolve Matrix Asset ID.

The use of the resolveMatrixAssetByURL utility requires session based auth enabled for the Content Management Content API.

// 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.