Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Describe htmlTag_stdWrap for hreflang usage #1332

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Documentation/Conditions/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ site()

.. code-block:: typoscript
:caption: EXT:site_package/Configuration/TypoScript/constants.typoscript

my.constant = my global value
[traverse(site('configuration'), 'settings/some/setting') == 'someValue']
my.constant = another value, if condition matches
Expand Down Expand Up @@ -1287,6 +1287,8 @@ siteLanguage()
fallback.

Returns the language information for the hreflang tag as a string.
If needed, you can use this attribute for the :html:`<html lang="...">`
attribute, see :confval:`htmlTag_stdWrap <config-htmltag-stdwrap>`.

:typoscript:`siteLanguage("fallbackType")`
Returns the language fallback mode as a string, one of `fallback`,
Expand Down
4 changes: 3 additions & 1 deletion Documentation/Functions/Data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,9 @@ siteLanguage
fallback.

The language tag for this language defined by RFC 1766 / 3066 for
:html:`hreflang` attributes
:html:`hreflang` attributes. If needed, you can use this attribute
for the :html:`<html lang="...">` attribute, see
:confval:`htmlTag_stdWrap <config-htmltag-stdwrap>`.

:typoscript:`languageId`
The language mapped to the ID of the site language.
Expand Down
13 changes: 13 additions & 0 deletions Documentation/TopLevelObjects/Config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,19 @@ Properties of 'config'
Modify the whole :html:`<html>` tag with stdWrap functionality. This can be
used to extend or override this tag.

For example it can be used to distinctly set a :html:`lang` attribute,
that may diverge from the automatically created attribute using the site
language settings. Normally, :html:`lang` is set to something like `en`
or `en`, only indicating the primary language. You may want to use the
garvinhicking marked this conversation as resolved.
Show resolved Hide resolved
:html:`hreflang` site language attribute instead (containing for example
`en-US`, `en-GB` or `de-AT`), which you can achieve via:

.. code-block:: typoscript
:caption: EXT:site_package/Configuration/TypoScript/setup.typoscript

config.htmlTag_stdWrap.override = <html lang="{siteLanguage:hreflang}">
config.htmlTag_stdWrap.override.insertData = 1
Comment on lines +567 to +568
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "override" which is a condition (if content is there, or not) I would prefer to use some more basic stdWrap property:

Suggested change
config.htmlTag_stdWrap.override = <html lang="{siteLanguage:hreflang}">
config.htmlTag_stdWrap.override.insertData = 1
config.htmlTag_stdWrap.dataWrap = <html lang="{siteLanguage:hreflang}">

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the codelines from Georg Ringer. I know too little of Integration with these codes, I am not sure what the reasoning was to use 'override' here, and if it would have benefits. Are you absolutely sure it would work with a dataWrap and has no side effects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are not working. My example will append an additional html-tag (which is wrong) and the one from Georg will remove all previously added html attributes and will not set the hreflang from site language. Instead it will show the hreflang from Locale object contained in SiteLanguage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so dump. If you work with:

config.htmlTag.attributes.class = specialHtmlTagClass

the solution from Georg will overwrite everything. So, this attribute is gone in Georgs solution. I remember some special tag properties from TypoScript. I tried with encapseLines, but as in $content <html lang="en_US"> is no ending <html> the tags property can not replace anything.

OK. I tries something very different: externalBlocks of parseFunc. It does not work either as HtmlParser_tags does not have stdWrap properties. So, I can also fixAttrib->set with fixed values.

So, currently only replacement seems to be an option:

config.htmlTag.attributes.garvin = hallo

config.htmlTag_stdWrap.replacement.10 {
  search = #lang="(.*?)"#i
  replace.dataWrap = lang="{SITE:languages.0.hreflang}"
  useRegExp = 1
}

Further problem is, that {siteLanguage:hreflang} will automatically be redirected into the sub-object Locale of Language object. But in Locale object still the original hreflang exists and not the modified version from Site Language object:

https://github.com/TYPO3/typo3/blob/main/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php#L4044-L4046

So, to get the hreflang property from Site Configuration (without Locale object) is to access all languages and extract the first one. See my example TS from above.

Is there anyone with another idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

override makes it already clear, that the tag is indeed overridden. If you want to have it fool proof add a comment that it is overriden and you might have to redefine other parameters. I would not use crazy constructs as most ppl hardly understand stdwrap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created an issue ticket: https://forge.typo3.org/issues/104987


.. confval:: index_descrLgd
:name: config-index-descrLgd
:type: :ref:`data-type-integer`
Expand Down
Loading