从文件中获取HTML并在模板中渲染?

发布于 2025-02-11 04:49:53 字数 812 浏览 1 评论 0原文

我有一个.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文