typoscript: do not show submenu if certain backend_layout is selected - typo3

I made a special panning sub menu with icons which can be inserted choosing a specific backend_layout named pagets__panmenu , if that layout is selected the main menu should not display a sub menu and link to the page instead of opening a sub ...
I work with typo3 V7.6.11 and fluid styled content
The part reading the value works correctly:
NO = 1
NO {
before.cObject = LOAD_REGISTER
before.cObject{
panmenu.cObject = TEXT
panmenu.cObject.data.dataWrap = DB:pages:{field:uid}:backend_layout
}
ATagBeforeWrap = 1
wrapItemAndSub = <li>|</li>
stdWrap.htmlSpecialChars = 1
}
This is my best effort to match, but its not working:
IFSUB <.NO
IFSUB {
wrapItemAndSub = <li class="dropdown">|</li>
wrapItemAndSub.override = <li>|</li>
wrapItemAndSub.override.if {
value.data = register:panmenu
equals = pagets__panmenu
}
ATagParams = class="dropdown-toggle" data-toggle="dropdown"
ATagBeforeWrap = 1
}
I know that also the 2 < .1 has to be suppressed, I'm trying to get the if to work to keep the style and link clean for starters ...

First of all: have you set TMENU.IFSUB = 1?
Else, everything you do in IFSUB won't have an effect.
Now some general thoughts:
a) Normally, backend layouts are used to switch an entire page template:
page.10 = FLUIDTEMPLATE
page.10 {
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = pagelayout
default = TEXT
default.value = {$myTemplatePath}/Standard.html
1 = TEXT
1.value = {$myTemplatePath}/Home.html
2 = TEXT
2.value = {$myTemplatePath}/Landing.html
}
layoutRootPath = {$myLayoutPath}
partialRootPath = {$myPartialPath}
}
So this initiates the frontend rendering for the entire page, where backend_layout with uid 1 will use the Home.html template, backend_layout with uid 2 will use the Landing.html template, and all others (=default) will use the Standard.html template.
If you build your site by this method, I would recommend doing
# that's the original version of your menu
lib.panmenu = HMENU
lib.panmenu {
// ...
}
# make a copy of the original
lib.panmenu_variant < lib.panmenu
# modify it as required
lib.panmenu_variant.1.NO {
// ...
}
Now, in your page Templates (which you call separately via the CASE from above), you can either use
<f:cObject typoscriptObjectPath="lib.panmenu" />
or
<f:cObject typoscriptObjectPath="lib.panmenu_variant" />
b) But if you don't want to follow that approach, you should also be able to use the backend_layout CASE on any cObject. The CASE variant has proven much more robust for me.
Here' how I'd try to get the CASE working (untested!)
// suppose temp.navigation_main is your full menu
temp.navigation_main_variant < temp.navigation_main
temp.navigation_main_variant {
// modify the menu as you please
10.2 >
10.1.IFSUB.wrapItemAndSub = <li>|</li>
}
// use lib.nav in your page
lib.nav = CASE
lib.nav {
key.data = pagelayout
// normally, lib.nav is the full navigation
default < lib.navigation_main
// except if be layout 1 is selected
1 < lib.navigation_main_variant
}
}
c) I've tried TypoScript constructions with LOAD_REGISTER and ifs years ago and they always made me go crazy. I wouldn't invest too much energy into them, as they rather seem to be legacy parameters than the future way of development for TYPO3 logic.

Related

Typo3 Custom filed on Content Element

Can I add a custom field to each content-element where I can add a string?
In typoscript I would be able to read this string and print it in class="" attribute is that possible?
There is the note field for each content element Can I red this in typoscript and paste it in the class attribute?
CONTENT < styles.content.get
CONTENT.renderObj.stdWrap.dataWrap=<div class="{NOTE??}">|</div>
Thanks
UPDATE:
Is something like this possible:
CONTENT < styles.content.get
CONTENT.renderObj.stdWrap {
key.field = layout
4 = TEXT
4.value = <div class="csc-default blue">|</div>
5 = TEXT
5.value = <div class="csc-default meineklasse2">|</div>
6 = TEXT
6.value = <div class="csc-default meineklasse3">|</div>
}
As to stay with a given CI it normally is no good option to enable editors to enter CSS-class names by hand. A better way would be to have a set of possible classes the editor can choose from.
This can be done if you use the already available field layout in the tt_contentrecord.
As the layoutfield is type int you might need a 'translation' to your expected class names, or you stay with numbered classes like frame-layout-1 to frame-layout-3. This is the (in FSC) build in solution and available option.
You can enhance this option and also modify it.
Enhancing the selection is done in page TSconfig:
// Adding more layouts:
TCEFORM.tt_content.layout.addItems {
4 = my special layout
5 = my other special layout
}
// Modifying layouts names:
TCEFORM.tt_content.layout.altLabels {
1 = my default layout
}
// remove items
TCEFORM.tt_content.layout.removeItems = 2,3
In FSC this field is evaluated in the layout template (Resources/Private/Layouts/Default.html) (if you also use a frame_class ????)
[...]
<div id="c{data.uid}" class="frame frame-{data.frame_class} frame-type-{data.CType} frame-layout-{data.layout}{f:if(condition: data.space_before_class, then: ' frame-space-before-{data.space_before_class}')}{f:if(condition: data.space_after_class, then: ' frame-space-after-{data.space_after_class}')}">
[...]
But you can override the Default.html file with your own, like in every fluid templating system. Just copy the original file to your own space and add the new location to the template (Layout) paths.
That could end in something like:
[...]
<div id="c{data.uid}" {f:render.section(name:'layout-selection', arguments={layout:'layout'})} ... >
[...]
<f:section name="layout-selection">
<f:switch expression="{layout}">
<f:case value="1">class="normal"</f:case>
<f:case value="4">class="special"</f:case>
<f:case value="5">class="very-special"</f:case>
<f:defaultCase>class="default"</f:defaultCase>
</f:switch>
</f:section>
based on the version of your TYPO3 the template paths of FSC can be configured like:
(up to TYPO3 7):
lib.fluidContent {
templateRootPaths {
20 = EXT:my_extension/Resources/Private/Templates/
}
partialRootPaths {
20 = EXT:my_extension/Resources/Private/Partials/
}
layoutRootPaths {
20 = EXT:my_extension/Resources/Private/Layouts/
}
}
or (since TYPO3 8): (Manual)
lib.contentElement {
templateRootPaths {
20 = EXT:my_extension/Resources/Private/Templates/
}
partialRootPaths {
20 = EXT:my_extension/Resources/Private/Partials/
}
layoutRootPaths {
20 = EXT:my_extension/Resources/Private/Layouts/
}
}
I found a solution which works for me.
tt_content.stdWrap.innerWrap.cObject = CASE
tt_content.stdWrap.innerWrap.cObject {
key.field = layout
4 = TEXT
4.value = <div class="blue"><div class="container-fluid"><div class="design">|</div></div></div>
5 = TEXT
5.value = <div class="white"><div class="container-fluid"><div class="design">|</div></div></div>
6 = TEXT
6.value = <div class="grey"><div class="container-fluid"><div class="design">|</div></div></div>
}

TYPO3 loading object based on current front end language

I'm running a Typo3 v9.5.4 Onepager style Website. The content is loaded directly from the tt_content. The Website has two FE languages (German/English).
I have a CTA button which has an anchorlink. The button is create with typoscript. I created one button for the German version and one for the English verson bc they have another value and another ancorlink.
I'm not sure if I can access a tt_content field directly from a fluid viewhelper. This is my code i've tried
<f:if condition="{tt_content.sys_language_uid} == 1">
<f:then>
<f:format.raw>{buttonEn}</f:format.raw>
</f:then>
<f:else>
<f:format.raw>{buttonDe}</f:format.raw>
</f:else>
</f:if>
This is my Typoscript for the two button Objects
lib.buttonDe = TEXT
lib.buttonDe {
value = German Text
stdWrap.typolink.parameter = #anchorlinkDE
stdWrap.typolink.ATagParams = class="button"
}
lib.buttonEn = TEXT
lib.buttonEn {
value = English Text
stdWrap.typolink.parameter = #anchorlinkEN
stdWrap.typolink.ATagParams = class="button"
}
And this is the typoscript that loads the Content, the Languages Menu and the Fluidtemplate (the Onepager Content is loaded without a Fluidtemplate, it loads the content directly from tt_content):
//--------------------- One Pager Content
lib.sectionContent = HMENU
lib.sectionContent {
excludeUidList = 12,13,16,17,29
1 = TMENU
1 {
NO = 1
NO {
doNotLinkIt = 1
stdWrap >
stdWrap {
cObject = COA
cObject {
if.value = 4
if.equals.field = doktype
if.negate = 1
10 < temp.titleSectionId
10.wrap = <section id="|">
20 = CONTENT
20 {
table = tt_content
select {
pidInList.field = uid
orderBy = colPos,sorting
# Only selects Content where CE Layout is 0
where = (tt_content.layout = "0")
}
wrap = <div class="container">|</div>
renderObj < tt_content
}
30 = TEXT
30 {
wrap = </section>
}
}
}
}
}
}
//---------------------
// Language Selector
lib.langmenu = HMENU
lib.langmenu {
special = language
addQueryString = 1
special.value = {$config.language.uids}
1 = TMENU
1 {
wrap = <ul class="dg-langmenu row">|</ul>
NO = 1
NO {
stdWrap.current = 1
stdWrap.setCurrent = {$config.language.labels}
allWrap = <li class="col s6">|</li>
}
ACT < .NO
ACT.doNotLinkIt = 1
ACT.allWrap = <li class="act col s6">|</li>
}
}
page = PAGE
page{
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName.stdWrap{
cObject = TEXT
cObject{
data = levelfield:-2,backend_layout_next_level,slide
override.field = backend_layout
split {
token = pagets__
1.current = 1
1.wrap = |
}
}
ifEmpty = onePager
}
templateRootPaths {
10 = {$path.privat}Templates/
}
layoutRootPaths {
10 = {$path.privat}Layouts/
}
partialRootPaths {
10 = {$path.privat}Partials/
}
variables{
buttonDe < lib.buttonDe
buttonEnd< lib.buttonEn
}
}
So I'd like to load the buttonEn if the content has the sys_language_uid 1 (English) else I want it to load the buttonDe.
Do I need to create an Typoscript Object and then load this Object into the f:if viewhelper? If so how do I create this Typoscript Object.
Thanks for your help!
The easy way (pure typoscript)
lib.button = TEXT
lib.button {
value = English text
lang.de = Deutscher Text
stdWrap.typolink.parameter = #anchorlinkDE
stdWrap.typolink.ATagParams = class="button"
}
[siteLanguage("locale") == "en_EN.UTF-8"]
lib.buton.stdWrap.typolink.parameter = #anchorlinkEN
[global]
but the professional solution is configuring your labels in a language file (see answer from Thomas Löffler) and use:
lib.button = TEXT
lib.button {
lib.button.data = LLL:EXT:site_extension/Resources/Private/Language/locallang.xlf:button_label
stdWrap.typolink.parameter = #anchorlinkEN
stdWrap.typolink.ATagParams = class="button"
}
[siteLanguage("locale") == "de_DE.UTF-8"]
lib.buton.stdWrap.typolink.parameter = #anchorlinkDE
[global]
For language dependent constant data you might use typoscript conditions to redefine a value for your non default languages. (or define a fallback and conditions for each language.)
You should use a locallang file and refer to it in TypoScript.
Create a locallang file (copy an existing and remove all values) named locallang.xlf
Add your english label in there
Create a locallang file in the same folder with prepending de. in the filename (de.locallang.xlf) and add the german label
Refer to it in the TypoScript by using lib.button.data = LLL:EXT:your_ext/path/to/locallang/locallang.xlf:buttonLabel, see https://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Index.html#lll
This TS getText function gets the label depending on the set language ID automatically and you only need one TS for the button.
Example: https://docs.typo3.org/typo3cms/TyposcriptIn45MinutesTutorial/UsingGetText/Index.html

Adding sections (anchors) to a fluid menu in typo3 with bootstrap_package

I would like to have a menu mixing pages and sections from current page.
For example on page1:
section1_from_page1
section2_from_page1
page2
page3
And on page2:
section1_from_page2
page1
page3
Until now, all I'm able to do is to build a new section menu with TypoScript :
lib.sectionnavigation = HMENU
lib.sectionnavigation {
1 = TMENU
1 {
sectionIndex = 1
sectionIndex.type = header
sectionIndex.useColPos = -1
NO {
ATagBeforeWrap = 1
linkWrap = <span> | </span> <span class="bar"></span>
allWrap = <li> | </li>
allWrap.insertData = 1
}
}
special = list
special.value.data = page:uid
}
And then add this menu in the Main.html partials from bootstrap_package, with f:cObject :
<f:cObject typoscriptObjectPath="lib.sectionnavigation" />
However, that means that I have to maintain "format" (<li><span>...</span><span class="bar"></span></li>) in both the TypoScript and the Main.html partial which is not convenient.
For example, if I change the menu so that I don't need the bar class span, I'll have to update the partial and the TypoScript!
From what I've understood, bootstrap_package defines the main menu in setup.txt:
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
levels = 2
includeSpacer = 1
as = mainnavigation
}
And then used this in the Main.html partial:
<f:for each="{mainnavigation}" as="mainnavigationItem">
My first plan was to try to built an new array (similar to the one in {mainnavigation}) using TypoScript but I couldn't find a way!
I also tried to use a MenuProcessor but didn't succeed either.
Any help would be really appreciated!
Thank you.
You should use the possibility to identify the current page in typoscript menus with the option to replace the complete rendering for a menu item.
The rendering for current page in a menu can be defined with ACT or CUR (ACT identifies all pages in the root line: current page, parent, grand parent, ...). In your case it may not differ, but you might play it safe:
lib.MainMenu = HMENU
lib.MainMenu {
wrap = <ul class="nav">|</ul>
1 = TMENU
1 {
NO {
wrapItemAndSub = <li><span> | </span> <span class="bar"></span></li>
}
CUR = 1
CUR.doNotShowLink = 1
// insert your section menu here:
CUR.before.cObject < lib.sectionnavigation
}
}

TYPO3: Backend Layout Condition in TypoScript

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
In TYPO3 7.5 "Backend Layout"-Conditions has been simplified with "pagelayout" in Typoscript. Example:
page.10 = FLUIDTEMPLATE
page.10 {
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = pagelayout
default = TEXT
default.value = EXT:sitepackage/Resources/Private/Templates/Home.html
3 = TEXT
3.value = EXT:sitepackage/Resources/Private/Templates/1-col.html
4 = TEXT
4.value = EXT:sitepackage/Resources/Private/Templates/2-col.html
}
}
Instead of:
field = backend_layout
field.data = levelfield:-2,backend_layout_next_level,slide
field.ifEmpty = default
Maybe this also works in your conditions like this:
[globalVar = TSFE:page|pagelayout = 1]
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.
In TYPO3 9.5+ you can use typoscript conditions like:
[page["backend_layout"] == 'pagets__2']
page.bodyTagCObject.value.wrap = <body id="uid|" class="fullpage">
[end]
Edit:
As Bernd has mentioned use backend_layout only if you need the real defined field. If you need the computed value (e.g. for a sub page getting its layout from the backend_layout_next_level from a parent page) use pagelayout with a case like:
bodyTagCObject = TEXT
bodyTagCObject.value.field = uid
bodyTagCObject.value.wrap.cObject = CASE
bodyTagCObject.value.wrap.cObject{
key.data = pagelayout
default = TEXT
default.value = <body id="uid|" class="standard">
pagets__2 = TEXT
pagets__2.value = <body id="uid|" class="fullpage">
}
We use this solution
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
templateName = TEXT
templateName.stdWrap {
cObject = TEXT
cObject {
data = levelfield:-2,backend_layout_next_level,slide
override.field = backend_layout
split {
token = pagets__
1.current = 1
1.wrap = |
}
}
ifEmpty = Index
}
layoutRootPaths {
10 = EXT:yourext/Resources/Private/Layouts
}
partialRootPaths {
10 = EXT:yourext/Resources/Private/Partials
}
templateRootPaths {
10 = EXT:yourext/Resources/Private/Templates
}
}
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:
mod.web_layout.BackendLayouts {
Blankpage {
title = Blankpage
name = Blankpage
icon = EXT:yourext/Resources/Public/Icons/BackendLayouts/Blankpage.jpg
config {
backend_layout {
colCount = 1
rowCount = 2
rows {
1 {
columns {
1 {
name = Nameofthecolumn
colPos = 0
colspan = 1
}
}
}
2 {
columns {
1 {
name = Nameofthesecondcolumn
colPos = 1
colspan = 1
}
}
}
}
}
}
}
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
page.10 = FLUIDTEMPLATE
page.10 {
templateName = TEXT
templateName.stdWrap.cObject = CASE
templateName.stdWrap.cObject {
key.data = pagelayout
....
As you can not handle the inherited layouts in conditions you need to use typoscript. My solution is this:
page.10 = FLUIDTEMPLATE
page.10 {
templateRootPaths.1 = {$resDir}/Private/Templates
partialRootPaths.1 = {$resDir}/Private/Partials
layoutRootPaths.1 = {$resDir}/Private/Layouts
templateName = TEXT
templateName.cObject = CASE
templateName.cObject {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
#Default Template
default = TEXT
default.value = subpage
# homepage
pagets__homepage = TEXT
pagets__homepage.value = homepage
pagets__subpage = TEXT
pagets__subpage.value = subpage
}
variables {
:
pageLayout = TEXT
pageLayout.data = levelfield:-1, backend_layout_next_level, slide
pageLayout.override.field = backend_layout
// since TYPO3 7 this already is computed by the core and this gives the same:
pageLayout = TEXT
pageLayout.data = pagelayout
:
}
}
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:
resDir = EXT:site_project1/Resources
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
<f:render partial="{pageLayout}/header" arguments="{_all}" />
TYPO3 11.x:
[tree.pagelayout == 2]
...
[global]
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Feature-88276-TypoScriptConditionForPageLayout.html

TYPO3 Special menu content element

I am working on TYPO3 6.2 and In a page I have added the content element "Special menu" with the the option Site map with selected page. I was able to render this with out any issues.For almost all pages I have added navigation title and obviously in the site map also this navigation title will be displayed.My requirement is that I want to show title instead of nav_title.Tried the below code and doesn't seems to work . Can any one help me with this?
tt_content.menu.20.2.1 {
NO {
stdWrap.cObject = COA
stdWrap.cObject {
10 = TEXT
10.field = subtitle
}
ATagTitle.field = subtitle
}
}
Any help would be appreciated.
Insert the following lines to the setup field of an ext-template at the page where you want to display the plugin "Special menu" with option "Site map" and wont to change link title to subtitle.
tt_content.menu.20.2 >
tt_content.menu.20.2 = HMENU
tt_content.menu.20.2.1 = TMENU
tt_content.menu.20.2.1 {
expAll = 1
wrap = <ul>|</ul>
NO{
wrapItemAndSub = <li>|</li>
stdWrap.htmlSpecialChars = 1
stdWrap.field = subtitle//title # add title of link subtitle or if empty title
ATagTitle.field = nav_title//title #title add tag title what you need
}
}
tt_content.menu.20.2.2 < tt_content.menu.20.2.1
tt_content.menu.20.2.3 < tt_content.menu.20.2.1
tt_content.menu.20.2.4 < tt_content.menu.20.2.1
Example http://www.typozone.com/index.php?id=96