top-think / think

ThinkPHP Framework ——十年匠心的高性能PHP框架
http://www.thinkphp.cn
Other
7.83k stars 1.62k forks source link

tp5.0 中如何实现模板字符串为 html 而非 text #948

Closed conero closed 5 years ago

conero commented 5 years ago

由于业务需求,需要通过配置将 html 文本渲染为真正的 HTML而非文本。我知道这种方式是一种不安全的方法,不过当下的业务需要这样做。看了一下 TP5.0 的文档,没有发现相关的解决方案!因此问一下,有没有这样的解决方法!

20190718095721

尝试过:

php

<?php
class A ...{
function index(){
....
$this->assign('html_str', '<p><span>many words.</span></p>');
....
}
}

模板


....
<body>
{$html_str}
<!-- raw 方法不存在-->
{$html_str | raw}

{php} echo $html_str; {php} ....

conero commented 5 years ago

It's a bad issue.