Typoscript HMENU special get available pages only - typo3

How to make this HMENU display only the available pages?
Hope it is clear: at the moment it displays links for pages that lead to a 404 - Page not found
20 = HMENU
20 {
special = language
special.value = 0,1,2,3,4,5,6
special.normalWhenNoLanguage = 0
1 = TMENU
1 {
wrap (
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
|
</div>
</div>
</div>
)
NO = 1
NO {
doNotLinkIt = 1
linkWrap = |
stdWrap {
typolink {
parameter.data = page:uid
additionalParams = &L=0 || &L=1 || &L=3 || &L=4 || &L=5 || &L=6 || &L=7 || &L=8 || &L=9
ATagParams = class="dropdown-item"
addQueryString = 1
addQueryString.exclude = L,id,no_cache
addQueryString.method = GET
no_cache = 0
}
}
}
ACT < .NO
ACT {
stdWrap {
typolink {
#Add class to disable already active language from dropdown items
ATagParams = class="disable-link-content"
}
}
}
USERDEF1 < .NO
USERDEF1 {
noLink = 1
}
USERDEF2 < .ACT
USERDEF2 {
noLink = 1
}
}
#2 < .1
#3 < .2
}
If more information is required please let me know..

there is no noLink option (although the manual of TYPO3 9 does include it in an example, which gets removed now)
use doNotLinkIt = 1
oh. as you already use it and generate the link on your own with stdWrap.typoLink you need to remove this link generation.

Related

Maintain hreflang external pages in typo3

I would like to maintain the hreflang for pages in Typo3 7.6.19.
This is not possible automatically, because the pages are external and different.
With Yoast-SEO this possibility (at least in my version) does not come along.
It is an old Typo3 version, so I cannot use the extension bgm_hreflang from the TER.
Anyone an idea?
The structure of the hreflang meta is known.
https://developers.google.com/search/docs/advanced/crawling/localized-versions
I think I found out. I checked at which position the hreflang was generated:
headerData {
10 = HMENU
10 {
special = language
special.value = 0,1
special.normalWhenNoLanguage = 0
1 = TMENU
1 {
NO = 1
NO {
stdWrap.cObject = TEXT
stdWrap.cObject {
value = de || en
}
linkWrap = <link rel="alternate" hreflang="|
doNotLinkIt = 1
after.cObject = TEXT
after.cObject {
stdWrap {
wrap = " href="|" />
typolink {
parameter.data = TSFE:id
#page:uid
additionalParams = &L=0 || &L=1
returnLast = url
forceAbsoluteUrl = 1
addQueryString = 1
addQueryString.method = GET
addQueryString.exclude = gclid,L,id,cHash,no_cache,backPid
}
}
}
}
CUR = 1
CUR.doNotShowLink = 1
# No Translation
USERDEF1 = 1
USERDEF1.doNotShowLink = 1
USERDEF2 < .CUR
}
}
}
And then overwritten by the template extension per page:
page.headerData.10 >
page.headerData.10 = TEXT
page.headerData.10.value (
(...)
<link rel="alternate" href="https://example.com/" hreflang="x-default" />
)
Of course, it would be nicer if the editor would only have to enter urls as HTML code, but for the moment it fits.

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"
}
}
}
}

IF condition TypoScript for cObject

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

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.