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

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

Related

Typoscript HMENU special get available pages only

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.

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

How to add title to breadcrumb from the database of extention in typo3?

Using kickstart i created one extension for listing category and product.And i need to display the both category title/name & product title/name in my breadcrumb .At present i coded for calling from the database(" 40 = RECORDS") it is only showing the
RESULT :- HOME > Page Name »
My Url:-http://www.domain.com/page_name/
lib.breadcrumb=COA
lib.breadcrumb {
40 = RECORDS
40 {
dontCheckPid = 1
tables = TABLE_NAME
source.data = GPvar:tx_pi1_NAME|EXTKEY
conf.EXTKEY = TEXT
conf.EXTKEY.field = FIELD_NAME
wrap = » |
}
10 = HMENU
10 {
special = rootline
# "not in menu pages" should show up in the breadcrumbs menu
includeNotInMenu = 1
1 = TMENU
# no unneccessary scripting.
1.noBlur = 1
# Current item should be unlinked
1.CUR = 1
1.target = _self
1.wrap = <div class="breadcrumb-class"> | </div>
1.NO {
stdWrap.field = title
ATagTitle.field = nav_title // title
linkWrap = ||*| > |*|
}
# Current menu item is unlinked
1.CUR {
stdWrap.field = title
linkWrap = ||*| &nbsp>&nbsp&nbsp |*|
doNotLinkIt = 1
}
}
}
Here is an example from the news extension. You can use the same approach for your extension.
http://forge.typo3.org/projects/extension-news/wiki/Add_news_to_breadcrumb_menu
We can add field title to breadcrumb from the database of any extention that which we create in typo3.
lib.breadcrumb = COA
lib.breadcrumb {
stdWrap.wrap = <ul class="breadcrumb">|</ul>
entryLevel = 1
10 = HMENU
10 {
special = rootline
1 = TMENU
1 {
noBlur = 1
NO = 1
NO {
wrapItemAndSub = <li>|</li>
ATagTitle.field = subtitle // title
linkWrap = ||*| ›&nbsp |*|
stdWrap.htmlSpecialChars = 1
}
CUR <.NO
CUR {
wrapItemAndSub = <li class="active">|</li>
}
}
}
101=RECORD
101 {
tables = tx_table_name
source.data = GPvar:tx_plugin_name|param //param passing in the url
conf.tx_besiproduct_product = TEXT
conf.tx_besiproduct_product.field = field_name
conf.tx_besiproduct_product.required = 1
conf.tx_besiproduct_product.wrap = <li >|</li>
}
}