Skip to content

Commit

Permalink
[FEATURE] Add option to influence display of the website title
Browse files Browse the repository at this point in the history
Adds a new TypoScript option config.showWebsiteTitle.
The option controls whether the website title (as defined
in the site configuration) is added to the page title,
which is e.g. used for the websites' title tag.

Resolves: #97653
Releases: main
Change-Id: I7bdde3db38f8e03023578f73e2c0968f8f40bb81
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74679
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Riccardo De Contardi <erredeco@gmail.com>
Tested-by: Tobias D. <tobias.doll@snk.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Tobias D. <tobias.doll@snk.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
TD authored and sbuerk committed May 23, 2022
1 parent 3669bf6 commit 361ddce
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. include:: /Includes.rst.txt

.. _feature-97653-1652873318
======================================================
Feature: #97653 - TypoScript Option "showWebsiteTitle"
======================================================

See :issue:`97653`

Description
===========

A new TypoScript option :typoscript:`config.showWebsiteTitle` has been added.

The option allows to define whether the website title, which is defined
in the site configuration, should be added to the page title, which is
e.g. used for the :html:`<title>` tag.

By default, the website title is added. To omit the website title, the
option has to be set to `0`.

Impact
======

It is now possible to influence the rendering of the website title in the
websites' title tag by setting the :typoscript:`config.showWebsiteTitle`
option, which is enabled by default, in TypoScript.

.. index:: Frontend, TypoScript, ext:frontend
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,8 @@ public function generatePageTitle(): string
$pageTitle,
(bool)($this->config['config']['noPageTitle'] ?? false),
(bool)($this->config['config']['pageTitleFirst'] ?? false),
$pageTitleSeparator
$pageTitleSeparator,
(bool)($this->config['config']['showWebsiteTitle'] ?? true)
);
$this->config['config']['pageTitle'] = $titleTagContent;
// stdWrap around the title tag
Expand All @@ -1972,28 +1973,27 @@ public function generatePageTitle(): string
* Compiles the content for the page <title> tag.
*
* @param string $pageTitle The input title string, typically the "title" field of a page's record.
* @param bool $noTitle If set, then only the site title is outputted
* @param bool $showTitleFirst If set, then website title and $title is swapped
* @param bool $noPageTitle If set, the page title will not be printed
* @param bool $showPageTitleFirst If set, website title and page title are swapped
* @param string $pageTitleSeparator an alternative to the ": " as the separator between site title and page title
* @param bool $showWebsiteTitle If set, the website title will be printed
* @return string The page title on the form "[website title]: [input-title]". Not htmlspecialchar()'ed.
* @see generatePageTitle()
*/
protected function printTitle(string $pageTitle, bool $noTitle = false, bool $showTitleFirst = false, string $pageTitleSeparator = ''): string
protected function printTitle(string $pageTitle, bool $noPageTitle = false, bool $showPageTitleFirst = false, string $pageTitleSeparator = '', bool $showWebsiteTitle = true): string
{
$websiteTitle = $this->getWebsiteTitle();
$pageTitle = $noTitle ? '' : $pageTitle;
if ($showTitleFirst) {
$temp = $websiteTitle;
$websiteTitle = $pageTitle;
$pageTitle = $temp;
}
$websiteTitle = $showWebsiteTitle ? $this->getWebsiteTitle() : '';
$pageTitle = $noPageTitle ? '' : $pageTitle;
// only show a separator if there are both site title and page title
if ($pageTitle === '' || $websiteTitle === '') {
$pageTitleSeparator = '';
} elseif (empty($pageTitleSeparator)) {
// use the default separator if non given
$pageTitleSeparator = ': ';
}
if ($showPageTitleFirst) {
return $pageTitle . $pageTitleSeparator . $websiteTitle;
}
return $websiteTitle . $pageTitleSeparator . $pageTitle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ page.typeNum = 0
config.noPageTitle = 2
[end]

[request.getQueryParams()['showWebsiteTitle'] == 0 || request.getParsedBody()['showWebsiteTitle'] == 0]
config.showWebsiteTitle = 0
[end]

[request.getQueryParams()['headerData'] == 1 || request.getParsedBody()['headerData'] == 1]
page.headerData.100 = TEXT
page.headerData.100.value = Header Data Title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,28 @@ public function titleTagDataProvider(): array
'assertNotRegExp' => '',
],
],
[
[
'pageId' => 1000,
'noPageTitle' => 1,
'showWebsiteTitle' => 0,
],
[
'assertRegExp' => '',
'assertNotRegExp' => '#<title>.*</title>#',
],
],
[
[
'pageId' => 1001,
'noPageTitle' => 1,
'showWebsiteTitle' => 0,
],
[
'assertRegExp' => '',
'assertNotRegExp' => '#<title>.*</title>#',
],
],
[
[
'pageId' => 1000,
Expand All @@ -148,6 +170,26 @@ public function titleTagDataProvider(): array
'assertNotRegExp' => '#<title>.*</title>#',
],
],
[
[
'pageId' => 1000,
'showWebsiteTitle' => 0,
],
[
'assertRegExp' => '#<title>Root 1000</title>#',
'assertNotRegExp' => '',
],
],
[
[
'pageId' => 1001,
'showWebsiteTitle' => 0,
],
[
'assertRegExp' => '#<title>SEO Root 1001</title>#',
'assertNotRegExp' => '',
],
],
[
[
'pageId' => 1000,
Expand Down Expand Up @@ -190,6 +232,17 @@ public function titleTagDataProvider(): array
'assertNotRegExp' => '',
],
],
[
[
'pageId' => 1000,
'pageTitleFirst' => 1,
'showWebsiteTitle' => 0,
],
[
'assertRegExp' => '#<title>Root 1000</title>#',
'assertNotRegExp' => '',
],
],
[
[
'pageId' => 1000,
Expand Down Expand Up @@ -227,6 +280,7 @@ public function checkIfCorrectTitleTagIsRendered(array $pageConfig, array $expec
'pageTitleTS' => (int)($pageConfig['pageTitleTS'] ?? 0),
'pageTitleFirst' => (int)($pageConfig['pageTitleFirst'] ?? 0),
'pageTitleSeparator' => $pageConfig['pageTitleSeparator'] ?? '',
'showWebsiteTitle' => (int)($pageConfig['showWebsiteTitle'] ?? 1),
])
);
$content = (string)$response->getBody();
Expand Down
6 changes: 5 additions & 1 deletion typo3/sysext/t3editor/Resources/Private/tsref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,14 @@ This is especially useful if you want to add RDFa or microformats to your html.
]]></default>
</property>
<property name="noPageTitle" type="int">
<description><![CDATA[If you only want to have the sitename (from the template record) in your <title> tag, set this to 1. If the value is 2 then the <title> tag is not printed at all.
<description><![CDATA[If you only want to have the website title (from the site configuration) in your <title> tag, set this to 1. If the value is 2 then the <title> tag is not printed at all.
Please take note that this tag is required for XHTML compliant output, so you should only disable this tag if you generate it manually already.]]></description>
<default><![CDATA[0]]></default>
</property>
<property name="showWebsiteTitle" type="int">
<description><![CDATA[If you want to omit the website title (from the site configuration) in your <title> tag, set this to 0.]]></description>
<default><![CDATA[1]]></default>
</property>
<property name="no_cache" type="boolean">
<description><![CDATA[If this is set to true, the page will not be cached. If set to false, it's ignored. Other parameters may have set it to true of other reasons.]]></description>
<default><![CDATA[-]]></default>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@
'showHistory': kw('showHistory'),
'showPageIdWithTitle': kw('showPageIdWithTitle'),
'showTagFreeClasses': kw('showTagFreeClasses'),
'showWebsiteTitle': kw('showWebsiteTitle'),
'simulateDate': kw('simulateDate'),
'simulateUserGroup': kw('simulateUserGroup'),
'singlePid': kw('singlePid'),
Expand Down

0 comments on commit 361ddce

Please sign in to comment.