Closed havutcuoglu closed 4 years ago
I think this is the nav_default
template of the core and you can easily customize it if needed.
I am not sure because the regular menu has the page tittle as title attribute, if there is no page title defined, then the nav template use the page name.
But the language switcher use only the page name also if you set the page title.
Or is there an another logic for root pages from Contao Core?
You are right, the core uses the following:
The Changelanguage Module however does not fill title
at all. Instead it fills pageTitle
with the title
of the page, which is not expected:
OK it uses title
instead of pageTitle
but i could not reproduce the use of Root-pageTitle
Did you forget to connect the translated pages?
My Titles are "Home"&"Startseite" / "Kontakt"&"Contact" etc...
And that mean, the root page use only the page name as title?
no - it's the same for regular pages.
OK it uses
pageTitle
instead oftitle
but i could not reproduce the use ofRoot-pageTitle
Did you forget to connect the translated pages?My Titles are "Home"&"Startseite" / "Kontakt"&"Contact" etc...
I didn't use any connection to any translated page. That mean the user will redirected to root page in the language he selected.
I will change now the nav_default for my problem but it is not the right way.
Check my Screenshot. You will see, the page title and page name is different. But the nav_template use the page name.
sorry i mixed that up title
/ pageTitle
https://github.com/terminal42/contao-changelanguage/blob/764854f733a3373ecf9be2d54518311bf2581f5a/library/Terminal42/ChangeLanguage/Navigation/NavigationItem.php#L235 should be switched i guess.
should be switched i guess.
No, see my comments. The core navigation module provides both title
and pageTitle
. The changelanguage module only provides pageTitle
, but fills it with the title
. The NavigationItem
class needs to be extended with
public function getPageTitle()
{
return $this->targetPage ? $this->targetPage->pageTitle : $this->rootPage->pageTitle;
}
and generateTemplateArray
needs to be changed as follows:
'isActive' => $item->isCurrentPage(),
'class' => 'lang-'.$item->getNormalizedLanguage().($item->isDirectFallback() ? '' : ' nofallback').($item->isCurrentPage() ? ' active' : ''),
'link' => $item->getLabel(),
'subitems' => '',
'href' => specialchars($item->getHref($urlParameterBag)),
+ 'title' => strip_tags($item->getTitle()),
- 'pageTitle' => strip_tags($item->getTitle()),
+ 'pageTitle' => strip_tags($item->getPageTitle()),
'accesskey' => '',
'tabindex' => '',
'nofollow' => false,
'target' => ($item->isNewWindow() ? ' target="_blank"' : '').' hreflang="'.$item->getLanguageTag().'" lang="'.$item->getLanguageTag().'"',
'item' => $item,
@havutcuoglu you could test these changes and make a PR accordingly.
The method 'pageTitle' => strip_tags($item->getPageTitle()),
doesn't work.
Here is the Error notice:
Attempted to call an undefined method named "getPageTitle" of class "Terminal42\ChangeLanguage\Navigation\NavigationItem". Did you mean to call "getTitle"?
UPDATE: Sorry I forget the function getPageTitle()
above :)
closed in favor of #180
The a-tag title has the page name as title.
Actually I have as page name: Root EN and as page title: My Company Inc.
The navigation menu generate the following source code:
<a href="mydomain" title="Root EN" class="lang-en nofallback" hreflang="en" lang="en" itemprop="url"><span itemprop="name">EN</span></a>
It is better to have the page title as title-tag if it's set.
Contao 4.9.3 Changelanguage 3.1.13