I'd like to change the way elements are rendered depending on the page's backend layout.
Changing the fluid styled content template depending on the backend layout works as following:
[globalVar = TSFE:page|backend_layout = 1][globalVar = TSFE:page|backend_layout = 2]
lib.fluidContent.templateRootPaths.10 = EXT:ds_res/Resources/Private/Templates/ContentTemplates/
[global]
If it's 1 or 2, then use the other templates.
However, this only works if the BE layout is set directly at the page and not when it's inherited from its parent.
How to fix this?
Running TYPO3 7.6.15
Thanks.
As you can not handle the inherited layouts in conditions you need to use typoscript. My solution is this:
Avoid using
file
for better implementation with ..RootPaths.As we use backendlayouts defined in files (which gets included in the pageTSconfig) the key names starting with
pagets__
, you also might use the numbers of backend_layout records.I use the constant
{$resDir}
to define the root of resources which can be changed in an easy way. In a siteextension this could be:I also define a fluid variable with the currently active page layout for further differentiation in the templates.
If you want the
...RootPaths
to be different for each layout you need to build cObject with a CASE obejct similar to my selection of the template name.In general: all this could be handled in the fluid templates if you have the backend layout available in your variables: you only need to have one starting template, which calls a layout where all further calls to partials are individualized by the current layout like
We use this solution
This approach is when u do not have the Backendlayouts in the DB (made through the backend) but include them from files. As there is no uid then you go by the templatename.
Example: If you use this PageTS:
You will need a Template.html with the name Blankpage.html within your EXT-Templates.
So you can add more Templates and Backendlayouts without touching the TS again. Simply add PageTS and a html-template.
There is a feature available which avoids having that code duplicated
In TYPO3 7.5 "Backend Layout"-Conditions has been simplified with "pagelayout" in Typoscript. Example:
Instead of:
Maybe this also works in your conditions like this:
However, you should not change the used template file with [xy]-conditions and prefer using a CASE shown in the example above. Each number is the UID of a
backend_layout
by the way.