IF condition TypoScript for cObject - typo3

I have HMENU and TMENU inside. For TMENU.NO.after property I need to dinamically assign cObject based on current page uid?
Code:
#Privatni podmeni
lib.meni= HMENU
lib.meni.special = list
lib.meni.special.value = 5395, 5396, 5397, 5398
lib.meni.wrap = <ul id="menu" style="display:none;">|</ul>
lib.meni.1 = TMENU
lib.meni.1{
expAll = 1
NO {
allWrap = <li>|</li>
ATagParams.insertData = 1
ATagParams = class="drop _{field:uid}"
after.cObject < temp.meni5
}
}
I need this in pseudo-code:
IF field:uid = 5240
after.cObject < temp.meni5
IF field:uid = 5241
after.cObject < temp.meni6
IF field:uid = 5342
after.cObject < temp.meni7
How can I do this?

You can use COA cObject and set it partially:
lib.meni.1.NO.after.cObject = COA
lib.meni.1.NO.after.cObject {
10 < temp.meni5
10.if.equals.field = uid
10.if.value = 5240
20 < temp.meni6
20.if.equals.field = uid
20.if.value = 5241
30 < temp.meni7
30.if.equals.field = uid
30.if.value = 5342
}
But this will work in case your objects in temp.meni5, temp.meni6, temp.meni7 support stdWrap. Check TSref for details.

I was able to get this done by using CASE object in TS. Here is example code:
temp.meni0= HMENU
temp.meni0.special = list
temp.meni0.special.value = 5417, 5418, 5419, 5420, 5421
temp.meni0.wrap = <div class="dropdown_5columns"><div class="col_1"><ul>|</ul></div></div>
temp.meni0.1 = TMENU
temp.meni0.1{
expAll = 1
NO {
allWrap = <li>|</li>
#ATagParams.insertData = 1
#ATagParams = class="drop"
}
}
temp.meni6= HMENU
temp.meni6 < temp.meni0
temp.meni6.special.value = 5431, 5432, 5433, 5434, 5435
temp.meni6.wrap = <div class="dropdown_5columns m-144"><div class="col_1"><ul>|</ul></div></div>
temp.meni7= HMENU
temp.meni7 < temp.meni0
temp.meni7.special.value = 5456, 5457, 5458, 5459, 5460
temp.meni7.wrap = <div class="dropdown_5columns m-288"><div class="col_1"><ul>|</ul></div></div>
temp.meni8= HMENU
temp.meni8 < temp.meni0
temp.meni8.special.value = 5466, 5467, 5470, 5471, 5472
temp.meni8.wrap = <div class="dropdown_5columns m-432"><div class="col_1"><ul>|</ul></div></div>
lib.meni= HMENU
lib.meni.special = list
lib.meni.special.value = 5395, 5396, 5397, 5398
lib.meni.wrap = <ul id="menu" style="display:none;">|</ul>
lib.meni.1 = TMENU
lib.meni.1{
expAll = 1
NO {
allWrap = <li>|</li>
ATagParams.insertData = 1
ATagParams = class="drop _{field:uid}"
#after.cObject < temp.meni5
after.cObject = CASE
after.cObject {
key.field = uid
default = TEXT
default.value = <span>NIJE OK!</span>
5395 < temp.meni0
5396 < temp.meni6
5397 < temp.meni7
5398 < temp.meni8
}
}
}
With this, I am able to insert very specific submenus for each menu item (page) of lib.menu

Related

TYPO3 TypoScript active rootNode in Webseite in Menu

I've got a TYPO3 page (6.2.31) and want to make the root node actvie in typoscript. roodnode is the globe.
my typoscript looks like this at the moment:
NAVIMAIN = HMENU
NAVIMAIN.entryLevel = 0
#NAVIMAIN.excludeUidList =
NAVIMAIN {
1 = TMENU
1 {
expAll = 1
wrap = <ul class="sf-menu">|</ul>
noBlur = 1
NO = 1
NO.ATagTitle.field = title
NO.wrapItemAndSub = <li>|</li>
ACT = 1
ACT.wrapItemAndSub = <li class="active"> |</li>
}
2 = TMENU
2 {
expAll = 1
maxItems = 10
wrap = <div class="sf-mega">|</div>
NO = 1
NO {
ATagTitle.field = title
wrapItemAndSub = <div class="sf-mega-section">|</div>
stdWrap.wrap = |
ATagParams = class="headermega"
stdWrap.htmlSpecialChars = 1
doNotLinkIt = 0
}
}
3 = TMENU
3 {
expAll = 1
maxItems = 20
wrap = <ul>|</ul>
NO = 1
NO {
ATagTitle.field = title
linkWrap = <li>|</li>
}
ACT = 1
ACT {
wrapItemAndSub = <li>|</li>
ATagParams = class="active"
}
}
#4 < .3
}
All other pages are marked as aktive. only the rood node not.
root node is the globe, there is one link (third) that redirects to root node
Whats my problem?
Thanks
I suppose you want the menu item (which links to your root node) stated as active.
With the TypoScript option alwaysActivePIDlist and a condition you can do that.
Example:
[globalVar = TSFE:id = <page uid of root node>]
NAVIMAIN.alwaysActivePIDlist = <page uid you want to set as active>
[global]

TYPO3 language menu with tx_news - hide language from menu if news record is not translated

I want to hide a language from my language menu if a news record is not translated.
The following setup works perfectly for pages. So if a page has no translation, the "English" is not shown in the language menu on the website.
I would like to have this behaviour for not translated news records as well.
The language menu so far:
lib.language = COA
lib.language {
20 = HMENU
20 {
special = language
special.value = 0,1
special.normalWhenNoLanguage = 0
wrap =
1 = TMENU
1 {
noBlur = 1
NO = 1
NO {
linkWrap = <li>|</li>
stdWrap.override = Deutsch || English
stdWrap {
typolink {
parameter.data = page:uid
additionalParams = &L=0 || &L=1
ATagParams = hreflang="de-DE" || hreflang="en-GB"
addQueryString = 1
addQueryString.exclude = L,id,cHash,no_cache
addQueryString.method = GET
useCacheHash = 1
no_cache = 0
}
}
}
ACT < .NO
ACT.linkWrap = <li class="active">|</li>
USERDEF1 = 1
USERDEF1 {
ldoNotLinkIt = 1
stdWrap.cObject = TEXT
stdWrap.cObject.value =
}
USERDEF2 = 1
USERDEF2 {
doNotLinkIt = 1
stdWrap.cObject = TEXT
stdWrap.cObject.value =
}
}
}
wrap = <ul id="language_menu" class="language-menu">|</ul>
}
My typoscript configuration:
config.sys_language_mode = strict
config.sys_language_overlay = hideNonTranslated
LocalConfiguration.php
[FE][hidePagesIfNotTranslatedByDefault] = 1
You have to manually set the USERDEF1 state. This Utility class should help: https://gist.github.com/birger-fuehne/a8a97c94ec9346d691174462ccbfcfcc

TYPO3 multi language. URL back to default when no translation. How to?

i am currently working on a project that requires two languages. For example German (L=0) and Leicht German (L=1).
My goal is, when there is a translation available on the German page to Leicht German, a button will appear and redirect the user to the Leicht German language. So far so good it works.
But, when you are on the Leicht German version and you want to move to another page where no Leicht German translation is available, by clicking on the submenu and not the button itself, the URL stays on the L=1 and it doesn't go back to L=0.
I would like your knowledge on this matter cause i am run out of ideas.
Here is my code:
config {
linkVars = L(0-1)
uniqueLinkVars = 1
defaultGetVars.L = 0
sys_language_uid = 0
sys_language_overlay = 1
language = de
locale_all = de-DE
}
[globalVar = GP:L = 1]
config {
sys_language_uid = 1
language = leichte Sprache
locale_all = de_DE.UTF-8
htmlTag_setParams = lang="ls" dir="ltr" class="no-js" }
[global]
This is my list where when you click you redirect to the Leicht German and backwards.
lib.language = COA
lib.language {
20 = HMENU
20 {
special = language
special.value = 0,1
special.normalWhenNoLanguage = 0
wrap = <ul class="languageMenu">|</ul>
1 = TMENU
1 {
noBlur = 1
NO = 1
NO {
linkWrap = <li>|</li>
stdWrap.override = Deutsch || Leichte Sprache
stdWrap {
typolink {
parameter.data = page:uid
additionalParams = &L=0 || &L=1
ATagParams = hreflang="de-DE" || hreflang="de-LS"
addQueryString = 1 addQueryString.exclude = L,id,cHash,no_cache
addQueryString.method = GET useCacheHash = 1
no_cache = 0
}
}
}
ACT < .NO
ACT.linkWrap = <li class="active">|</li>
USERDEF1 < .NO
USERDEF1 {
linkWrap = <li class="text-muted">|</li>
stdWrap.typolink >
}
}
}
}
This is the submenu where when you click and no translation is available it should redirect the user to the default language (L=0)
lib.subnav = HMENU
lib.subnav.entryLevel = 1
lib.subnav {
1 = TMENU
1 {
wrap = <ul class="side-nav">|</ul>
noBlur = 1
NO = 1
NO {
wrapItemAndSub = <li>|</li>
ATagTitle.field = title
typolink {
parameter.data = page:uid
additionalParams = &L=0 || &L=1
ATagParams = hreflang="de-DE" || hreflang="de-LS"
addQueryString = 1 addQueryString.exclude = L,id,cHash,no_cache
addQueryString.method = GET
useCacheHash = 1
no_cache = 0
}
}
ACT < .NO ACT {
ATagParams = class="active" wrapItemAndSub = <li class="active">|</li>
}
}
At this point i have nothing else to add. If you need more from me, feel free to ask.
Thanks in advance,
Aris
did you try this, just let typo3 take care of the link:
lib.subnav = COA
lib.subnav {
10 = HMENU
10 {
entryLevel = 1
1 = TMENU
1 {
expAll = 1
wrap = <ul class="side-nav">|</ul>
noBlur = 1
NO = 1
NO {
wrapItemAndSub = <li>|</li>
ATagParams = title="{field:title}"
ATagParams.insertData = 1
}
ACT < .NO
ACT {
wrapItemAndSub = <li class="active">|</li>
ATagParams = class="active"
}
}
}
}

typo3: mark link in sitemap with dateUntil

I have a problem with marking a link in a Stiemap with dateUntil. Here is my typoscript:
tt_content.menu.20.1 >
tt_content.menu.20.1 < tt_content.menu.20.7
tt_content.menu.20.1.1.wrap = <div class="menu_list_sitemap">|</div>
tt_content.menu.20.1.1.NO {
ATagBeforeWrap = 0
doNotLinkIt = 1
stdWrap.htmlSpecialChars = 0
stdWrap.cObject = COA
stdWrap.cObject {
# Untertitel verlinken
10 = TEXT
10 {
field = subtitle
wrap = |
stdWrap.cObject = COA
stdWrap.cObject {
20 = IMAGE
20.file.import.field = media
20.file.import = uploads/media/
20.file.import.listNum = 0
20.wrap = |
30 = TEXT
30.field = title
30.wrap = <div class="txt">|</div>
40 = TEXT
40.if.isPositive.dataWrap = {field:newUntil}-{date:U}
40.wrap = <div class="txt2">|</div>
40.value = NEW
}
typolink.parameter.field = uid
}
}
}
The result is, that the new entries will get an additional div-container with class="txt2". Wokrs fine so far. :-) Here the generated HTML:
<li>
<a href="link-to-my-page">
<img width="22" height="22" alt="" src="my-image.png">
<div class="txt">My-Text</div>
<div class="txt2">NEW</div>
</a>
</li>
But now I need to add a "class='new'" to the Link or optional to a surrounding div-container (not my idea, really). I tried now for some hours to find a solution, but nothing worked.
Any suggestions?
i guess ATagParams would do the job. Use if to add only if needed
tt_content.menu.20.1 >
tt_content.menu.20.1 < tt_content.menu.20.7
tt_content.menu.20.1.1.wrap = <div class="menu_list_sitemap">|</div>
tt_content.menu.20.1.1.NO {
ATagBeforeWrap = 0
doNotLinkIt = 1
stdWrap.htmlSpecialChars = 0
stdWrap.cObject = COA
stdWrap.cObject {
# Untertitel verlinken
10 = TEXT
10 {
field = subtitle
wrap = |
### snip ###
typolink.parameter.field = uid
typolink.ATagParams = class="new"
typolink.ATagParams.if.isPositive.dataWrap = {field:newUntil}-{date:U}
}
}
}

Put the menu link url in an attribute

I need to make a menu without any links but with the url in an attribute.
The url should be in data-href="|" but now only the title will be printed in the attribute.
Is there a way to only return the url and not the link. ie. http://example.com instead of Example
Or does anyone know a different solution?
lib.mainMenu = HMENU
lib.mainMenu {
entryLevel = 1
wrap = <ul id="dropDownMenu">|</ul>
1 = TMENU
1 {
noBlur = 1
expAll = 1
NO = 1
NO {
wrapItemAndSub = <li class="nochildren">|</li>
stdWrap2.wrap = <span>|</span>
}
ACT < .NO
ACT.wrapItemAndSub = <li class="active nochildren">|</li>
# if has children
IFSUB < .NO
IFSUB.wrapItemAndSub = <li class="haschildren">|</li>
IFSUB.allWrap = |
# if has children and is active
ACTIFSUB < .IFSUB
ACTIFSUB.wrapItemAndSub = <li class="active haschildren">|</li>
ACTIFSUB.allWrap = |
}
2 < .1
2 {
wrap = <ul id="subMenu">|</ul>
NO.ATagParams = rel="nofollow"
NO.stdWrap2.insertData = 1
NO.stdWrap2.wrap = <span data-href="|" class="link">{field:title}</span>
NO.doNotLinkIt = 1
IFSUB < .NO
ACTIFSUB < .IFSUB
}
3 < .2
}
Try this (untested code):
lib.mainMenu = HMENU
lib.mainMenu {
entryLevel = 1
wrap = <ul id="dropDownMenu">|</ul>
1 = TMENU
1 {
noBlur = 1
expAll = 1
NO = 1
NO {
wrapItemAndSub = <li class="nochildren">|</li>
stdWrap2.wrap = <span>|</span>
}
ACT < .NO
ACT.wrapItemAndSub = <li class="active nochildren">|</li>
# if has children
IFSUB < .NO
IFSUB.wrapItemAndSub = <li class="haschildren">|</li>
IFSUB.allWrap = |
# if has children and is active
ACTIFSUB < .IFSUB
ACTIFSUB.wrapItemAndSub = <li class="active haschildren">|</li>
ACTIFSUB.allWrap = |
}
2 < .1
2 {
wrap = <ul id="subMenu">|</ul>
NO {
doNotShowLink = 1
stdWrap2 {
wrap >
cObject = TEXT
cObject {
typolink {
parameter.field = uid
returnLast = url
}
insertData = 1
wrap = <span data-href="|" class="link">{field:nav_title//field:title}</span>
}
}
}
IFSUB < .NO
ACTIFSUB < .IFSUB
}
3 < .2
}
The above answer only works as long as you don't have any mountpoints. As soon as you have mountpoints in your page tree, these links will not be generated correctly.
To force a HMENU to output plain URLs without a surrounding a-Tag and page title even when using mountpoints, you need to define the IProcFunc property of HMENU.
I've written a small method which can be called through IProcFunc which will remove the a-Tags and replace the page title with the URL of the link.
<?php
class UserFuncUtils {
/**
* Modifies sitemap links. Whith this modification, a menu will only generate a plain url instead of an <a>-Tag
*
* This is an IProcFunc for a HMENU. The only parameter supplied by this method call is $this->I from the
* Menu ContentObject. The function call expects a modified $I array to be returned.
*/
function IProcFunc_plainURL($I) {
// Show what $I has to offer
// print \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($I, NULL, 8, FALSE, FALSE, FALSE, array(), array());
// Remove opening and closing tags and replace title with href attribute. This results in a plain URL being rendered by the menu
$I['parts']['ATag_begin'] = '';
$I['parts']['ATag_end'] = '';
$I['parts']['title'] = $I['linkHREF']['HREF'];
return $I;
}
}
?>
Just save this small class somewhere (e.g. /fileadmin/libs/class.userFuncUtils.php) and include it with
includeLibs.userFuncUtils = fileadmin/libs/class.userFuncUtils.php
and then set the IProcFunc property of HMENU to point to this user function
lib.mainMenu = HMENU
lib.mainMenu.IProcFunc = UserFuncUtils->IProcFunc_plainURL
This should do the trick.