twig striptags and html special chars(树枝条带标签和 html 特殊字符)
问题描述
我正在使用 twig 来呈现视图,并且正在使用 striptags 过滤器来删除 html 标签.但是,html 特殊字符现在呈现为文本,因为整个元素都被 "" 包围.如何在仍然使用 striptags 功能的同时去除特殊字符或渲染它们?
I am using twig to render a view and I am using the striptags filter to remove html tags. However, html special chars are now rendered as text as the whole element is surrounded by "". How can I either strip special chars or render them, while still using the striptags function ?
例子:
{{ organization.content|striptags(" >")|truncate(200, '...') }}
或
{{ organization.content|striptags|truncate(200, '...') }}
输出:
"QUI SOMMES NOUS ? > NOS LOCAUXNOS LOCAUXDepuis 1995, Ce lieu chargé d’histoire et de tradition s’inscrit dans les valeurs"
推荐答案
如果它可以帮助别人,这是我的解决方案
If it could help someone else, here is my solution
{{ organization.content|striptags|convert_encoding('UTF-8', 'HTML-ENTITIES') }}
您还可以添加修剪过滤器以删除前后的空格.然后,您截断或切片您的组织内容.
You can also add a trim filter to remove spaces before and after. And then, you truncate or slice your organization.content
2017 年 11 月编辑
如果你想保持 " " 换行符与截断相结合,你可以这样做
If you want to keep the " " break lines combined with a truncate, you can do
{{ organization.content|striptags|truncate(140, true, '...')|raw|nl2br }}
这篇关于树枝条带标签和 html 特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:树枝条带标签和 html 特殊字符


基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01