headless icon indicating copy to clipboard operation
headless copied to clipboard

Document how to use fluid and headless at the same time

Open lukaszuznanski opened this issue 2 years ago • 5 comments

lukaszuznanski avatar Aug 10 '22 11:08 lukaszuznanski

Would love to have this feature documented! Would be very handy in one of my upcoming projects 😇

svenpet90 avatar Apr 05 '23 06:04 svenpet90

The main problem is that by including headless TypoScript configuration, the page configuration gets overwritten. I'd rather like to use a separate page type num.

cweiske avatar Oct 18 '23 12:10 cweiske

I needed both HTML and JSON output, and did not want to manually include single .typoscript configuration files from headless - because that would probably break with the next headless version.

Instead I opted for a TypoScript condition to only include headless configuration when the JSON page type is present. Conditional TypoScript file includes differ between TYPO3 v11 and v12: v12 supports @import inside conditions, while v11 always includes @import even if they are inside a condition. Using the old INCLUDE_TYPOSCRIPT is the only way to conditional include .typoscript files in v11 v11 docs, v12 docs, v12 typoscript changelog.

Since I am on v11 I used the following code:

<INCLUDE_TYPOSCRIPT: source="FILE:EXT:example/Configuration/ApiTypoScript/setup.typoscript" condition="[getTSFE() && getTSFE().type == 2]">
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:example/Configuration/TypoScript/setup.html.typoscript" condition="[getTSFE() && getTSFE().type != 2]">

(I renamed my original setup.typoscript to setup.html.typoscript)

My ApiTypoScript/setup.typoscript imports the headless setup.typoscript and sets the typeNum for page.

getTSFE().type is necessary, because request.getQueryParams()['type'] does not work with PageTypeSuffix site configuration for nice speaking URLs.

(I am using headless 3.4.0)

cweiske avatar Oct 19 '23 12:10 cweiske

isn't https://github.com/TYPO3-Headless/headless/pull/652 also related?

tmotyl avatar Oct 19 '23 14:10 tmotyl

Yes, it is, also it's merged to master, this is PR to 3.x branch.

lukaszuznanski avatar Oct 23 '23 11:10 lukaszuznanski