Search code examples
htmltypo3typoscriptfluid

TYPO3 HTML5 closing tags


I have set the following in the typoscript:

config.doctype = html5

nevertheless I get the following output:

<meta http-equiv="x-ua-compatible" content="IE=edge" />
<meta name="generator" content="TYPO3 CMS" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="index, follow" />
<meta name="author" content="test" />
<meta name="keywords" content="TYPO3" />
<meta name="description" content="Bootstrap" />
<meta name="twitter:card" content="summary" />

I want to remove the slashes at the end. How can I do that?

I also get the slash on some content items

<img class="image-embed-item" title="title" alt="alt" width="50" height="50" loading="lazy" />

that should also be removed. What is the best way to proceed?


Solution

  • I also think, that this is waste of time. But if you really need to do this you could add the meta-data via TypoScript headerdata:

    page.headerData {
    10 = TEXT
    10.value (
        <meta http-equiv="x-ua-compatible" content="IE=edge">
        <meta name="generator" content="TYPO3 CMS">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="robots" content="index, follow">
        <meta name="author" content="test">
        <meta name="keywords" content="TYPO3">
        <meta name="description" content="Bootstrap">
        <meta name="twitter:card" content="summary">
    )
    

    }

    Check in the TypoScript-Object-Browser if 10 is occupied before. In case it is use a free number. (i.e. 20 ;-)

    To remove the slash in the image tag, i think the only way is to implement your own viewhelper. Maybe you could xclass the tag-based-viewhelper to achive non-closing tags for all tag-based viewhelper.

    EDIT:

    If all that doesn't fit your requirements, the only way i see is to implement a middleware to remove all the closing tags.

    First implement the configuration in your extension.

    /Configuration/RequestMiddlewares.php

    <?php
    
    return [
        'frontend' => [
            'remove-closing-tags-middleware' => [
                'target' => \VENDOR\ExtName\Middleware\RemoveClosingTagsMiddleware::class,
                'after' => [
                    // Check Configuration for middlewares in Backend and replace last-middleware
                    // as described here: https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html#debugging
                    'last-middleware',
                ]
            ],
        ]
    ];
    

    And then implement the middleware in your extension.

    /Classes/Middleware/RemoveClosingTagsMiddleware.php

    <?php
    namespace VENDOR\ExtName\Middleware;
    
    use Psr\Http\Message\ResponseInterface;
    use Psr\Http\Message\ServerRequestInterface;
    use Psr\Http\Server\MiddlewareInterface;
    use Psr\Http\Server\RequestHandlerInterface;
    use TYPO3\CMS\Core\Http\NullResponse;
    use TYPO3\CMS\Core\Http\Stream;
    
    class RemoveClosingTagsMiddleware implements MiddlewareInterface
    {
    
    
        public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
        {
            $response = $handler->handle($request);
            if ($response instanceof NullResponse) {
                return $response;
            }
            $body = $response->getBody();
            $body->rewind();
            $content = $response->getBody()->getContents();
            $content = str_replace('/>', '>', $content);
            $body = new Stream('php://temp', 'rw');
            $body->write($content);
            return $response->withBody($body);
        }
    }
    

    Don't forget to adjust VENDOR and ExtName to your extension.

    Further information can be found here:

    https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html

    and here:

    https://reelworx.at/blog/detail/correct-manipulation-of-generated-html-in-typo3/