防止 TYPO3 Fluid 模板中变量的 htmlspecialchars

Prevent htmlspecialchars on variables in TYPO3 Fluid template

在命令控制器中,我使用 StandaloneView 创建一个纯文本文件。我为此使用的(简化)代码是:

$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setFormat('txt');
$view->setTemplatePathAndFilename('EXT:myext/Resources/Private/Templates/test.txt');
$view->assignMultiple([
    'test' => 'test&test',
]);
$content = $view->render();

如果模板只是 {test},结果内容是 test&amp;test,我希望 html 格式,但不是 txt。我试过将格式设置为 txttexttext/plain,但这不会影响结果。我知道我可以使用 <f:format.raw>,但是如果格式不是 html,是否有其他方法可以防止 HTML 字符被转义?

我正在使用 TYPO3 10.4.20。

您可以禁用输出转义:

<!-- Disabling HTML escaping for an entire file -->
{escaping off}

Any variables you render will not need to use f:format.raw
even if they contain special HTML entities. Useful when
you render formats other than HTML; or when you completely
trust (read: escaped before assigning to view) all your
variables that get output.

Use with care - caveat emptor!

( https://werkraum.net/devblog/fluid-tipp-8-html-escaping-deaktivieren/ )