我與樹枝模板的關(guān)系有問題。它返回原始 html 字符而不是 html 標記。<?php/* HomepageController.php */namespace App\Controller;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Response;class HomepageController extends AbstractController{ /** * @Route("/homepage/") */ public function homepage() { return $this->render('homepage/homepage.html.twig', [ 'title' => 'this will be title', ]); }}homepage.html.twig<h1>this should show html content</h1> <p>{{ title }} </p>瀏覽器輸出<h1>this should show html content</h1> <p>this will be title </p>樹枝.yamltwig: default_path: '%kernel.project_dir%/templates' debug: '%kernel.debug%' strict_variables: '%kernel.debug%' exception_controller: null你知道我要設(shè)置的配置是什么嗎
2 回答

偶然的你
TA貢獻1841條經(jīng)驗 獲得超3個贊
這是因為文件中設(shè)置了優(yōu)先級。就像json一樣。添加了html并且它起作用了。
fos.rest.yaml
format_listener:
rules:
- {
path: "^/",
priorities: ["json","html"],
fallback_format: json,
prefer_extension: false,
}

慕斯709654
TA貢獻1840條經(jīng)驗 獲得超5個贊
通常,twig 會將所有適用的字符轉(zhuǎn)換為 html 實體(另請參見PHP 文檔中的html_entites)。
如果您希望 twig 不進行此轉(zhuǎn)換,則需要|raw
在變量后面添加(例如{{ code|raw }}
.
此默認行為背后的原因是為了防止用戶將惡意代碼注入您的網(wǎng)站(例如,包括 javascript 代碼)。
提示:盡量避免變量中的 html 代碼。如果不可能,請確保該值不能包含來自用戶輸入的 html。
- 2 回答
- 0 關(guān)注
- 122 瀏覽
添加回答
舉報
0/150
提交
取消