Context URL
| This utility is only available for Components at Edge. |
The context object exposes the current URL on which a component is rendering.
This approach is useful when you want to implement content decisions that either:
-
Rely on knowing the current location of a site
-
Retrieve additional data about the parent page from Matrix.
Usage
|
The recommended method for retrieving additional data using the URL is the resolveMatrixAssetByUrl utility.
For more information read Resolve Matrix Asset URL.
// A simple "Page Header" component.
export default {
async main({}, info) {
const currentUrl = info.ctx.url; (1)
const data = await 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 URL from the context object. |
| 2 | Retrieve asset data from Content Management system. |
| 3 | Print a banner using the returned asset data. |