fetchContent

Learn how to fetch the content of a slot.

This method fetches the personalized content of a Slot to render in your application.

For more information, see the Content rendering reference.

Signature

This method has the following signature:

public function fetchContent(string $slotId, ?FetchOptions $options = null): FetchResponse

This method returns a FetchResponse with the resolved content. If the request fails and no fallback is set, it throws a CroctException.

Example

Here is a basic example of how to use this method:

<?phpuse Croct\Plug\Croct;
$croct = Croct::fromDotenv();$response = $croct->fetchContent('home-hero');

Parameters

The following list describes the supported parameters:

slotId
string

The ID of the slot to fetch, optionally including a version in the form <id>@<version>.

options(optional)

The fetch options, such as a fallback, preferred locale, version, or attributes.