英文:
TYPO3 HTML5 closing tags
问题
我已经在typoscript中设置了以下内容:
config.doctype = html5
然而,我仍然得到以下输出:
<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" />
我想要移除末尾的斜杠。我该如何做?
我还在一些内容项上得到了斜杠:
<img class="image-embed-item" title="title" alt="alt" width="50" height="50" loading="lazy" />
这也应该被移除。最佳操作方法是什么?
英文:
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?
答案1
得分: 1
以下是您要翻译的内容:
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/
英文:
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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论