从文件中获取HTML并在模板中渲染?
我有一个.txt文件,其中包含一些数据,但包裹在HTML标签中。
例如,在我的文本中,文件是< h3> header</h3> < button> button</button>
。
我希望看到一个格式的标头和HTML按钮。 但是我以的方式获得了纯文本,< h3> header</h3>< button> button>/butt</button>“
我已经在PHP Process文件中创建了一个变量。
$data["imported_data"] = file_get_contents($file);
在我的树枝模板中,我称之为变量。
<div class="container">
{{ imported_data }}
</div>
将文件中的文本拉开,但HTML被显示而不是格式化。 i尝试的{{imported_data | RAW}}
没有更改任何内容。 还尝试了下面无效的下面。
{% autoescape false %}
{{ imported_data | raw }}
{% endautoescape %}
并尝试了htmlentities(file_get_contents($ file));
但是HTML仍然没有格式化。
如何使树枝模板格式化HTML?
谢谢
I have a .txt file which contains some data, but wrapped in html tags.
For example, in my text file is <h3>Header</h3> <button>button</button>
.
I'm expecting to see a formatted header and a HTML button.
But I get plain text as "<h3>Header</h3> <button>button</button>"
I have created a variable in a php process file.
$data["imported_data"] = file_get_contents($file);
In my twig template I have called the variable.
<div class="container">
{{ imported_data }}
</div>
The text from the file is pulled through but the html gets displated instead of formatted.
I the tried {{ imported_data | raw }}
which didn't change anything.
Have also tried the below which didn't work.
{% autoescape false %}
{{ imported_data | raw }}
{% endautoescape %}
And also tried htmlentities(file_get_contents($file));
But still the html isn't formatted.
How can I get the twig template to format the html?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论