Project

General

Profile

Actions

Feature #95629

closed

Provide ViewHelper for PageTitleAPI

Added by Jonas Eberle about 3 years ago. Updated about 3 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
SEO
Target version:
-
Start date:
2021-10-13
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

The PageTitleAPI works great for any kind of pages or records and is used by many extensions.

For SEO and accessiblity reasons it makes sense to output an <h1> in the main page layout, but to my knowledge we don't have an out-of-the-box way to use the PageTitle value in a Fluid template.

A ViewHelper could look like this:

use TYPO3\CMS\Core\PageTitle\PageTitleProviderManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class PageTitleViewHelper extends AbstractViewHelper
{
    public static function renderStatic(
        array $arguments,
        \Closure $renderChildrenClosure,
        RenderingContextInterface $renderingContext
    ) {
        return GeneralUtility::makeInstance(PageTitleProviderManager::class)->getTitle();
    }
}
Actions #1

Updated by Georg Ringer about 3 years ago

  • Status changed from New to Needs Feedback

the page title is the one shown in the <title> tag. this is often not the one which is shown in a h1 as those can be 2 different things. I don't really get why you need the Page title in your template?

Actions #2

Updated by Jonas Eberle about 3 years ago

The <title> is additionally processed by the *pageTitle* options (https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Setup/Config/Index.html#pagetitle) and for example changed to "Website Title – Page Title".

PageTitle is a good default for a <h1> because of its pretty fallback nature thus having a valid title even for "record detail" plugins.

In order to help accessibility it makes sense to default to outputting a sensible <h1> everywhere and not rely on the editors as it should be a single instance only.

In some layouts it is necessary to output the `<h1>` in the page layout because it is in another place than the main content.

We could do that by

  • an additional colPos just containing for example a "header" element
  • a TypoScript lib but I don't think I could PageTitle API without a `userFunc` but before PageTitle API we did that (with additions for each "record detail" plugin)
  • or as suggested by a Fluid ViewHelper

Caveat: for both the TypoScript and ViewHelper approaches we need to actually render the content first (into a variable) so that PHP code in plugins is able to change the PageTitle.

Does that answer your question? It is basically a way to automatically output a title without having to manually add content (e.g. CType "header") for it and having to deal differently with "record detail" pages. PageTitle API opened that way and we could profit from it here.

Actions #3

Updated by Richard Haeser about 3 years ago

I agree with Georg. Page titles and H1's are most of the time (slightly) different as it has a different purpose. A page title is used for search results to trigger possible visitors to visit your site. The H1 is for people to tell them where this page is about. Although they might be the same sometimes (especially when you do not optimize for SEO that much), you can better use the title of the page as the H1 is my experience.

Nevertheless, I don't think this should be a feature for core TBH. It can be in a separate extension though.

Actions #4

Updated by Jonas Eberle about 3 years ago

  • Status changed from Needs Feedback to Rejected

I don't agree but ok. I'll close here.

Actions #5

Updated by Jonas Eberle about 3 years ago

Just an afterthought: Here's an extension that provides the Page Title in TypoScript: https://github.com/undkonsorten/typo3-pagetitle-ts#readme

Actions

Also available in: Atom PDF