Snippets 

Drop-in recipes for the most common questions.

Customise file output (URL signing, focus point, etc.) 

Listen to EnrichFileDataEvent. See Events you can listen to.

Override the JSON form output 

Implement FriendsOfTYPO3HeadlessFormDecoratorDefinitionDecoratorInterface or extend AbstractFormDefinitionDecorator, then point the form's renderingOptions.formDecorator at it. See EXT:form.

Add a JSON field to every page response 

Extend the page object in TypoScript (loaded after the set):

page.10.fields {
  myField = TEXT
  myField.value = static value
  myDynamic = TEXT
  myDynamic.data = TSFE:id
}
Copied!

Read the current site's frontend URL 

Inject FriendsOfTYPO3HeadlessUtilityHeadlessFrontendUrlInterface and call withRequest($request)->getFrontendUrl(). Returns the configured frontendBase for the active site and language.

Detect headless mode in your own code 

Inject FriendsOfTYPO3HeadlessUtilityHeadlessModeInterface and call isEnabledFor($request). FULL mode always returns true; MIXED mode only when the request's first Accept header value is exactly application/json (the strict match is the API contract).

Encode JSON safely from your own code 

Inject FriendsOfTYPO3HeadlessJsonJsonEncoderInterface instead of calling json_encode directly. It applies HTML-attribute-safe hex flags (JSON_HEX_APOS | JSON_HEX_AMP) and the headless.prettyPrint feature flag for free. Note that it does not throw on encoding failures — a JsonException is caught, logged as critical, and the string "[]" is returned instead.

Decode nested JSON inside an array 

Inject FriendsOfTYPO3HeadlessJsonJsonDecoderInterface and call decode($array). Any string value that looks like JSON gets decoded (nested structures come back as stdClass objects, the outer array stays an array). Useful when stitching multiple JSON cObjects together.

Process a file with the same shape as the default response 

Inject FriendsOfTYPO3HeadlessUtilityFileUtilityInterface and call process($fileReference, ProcessingConfiguration::fromOptions($opts)). The output matches what content elements receive — your custom endpoints stay shape-compatible with the rest of the JSON API.