Drupal 7 Views - 如何在字段标签内使用 HTML 代码?
视图中的字段标签假设纯文本输入,并且它们可能使用 check_plain() 来编码特殊字符(实际上没有查看视图后端)。
如何在标签内使用 HTML 代码?
编辑:我认为我的问题很清楚。我不想重写字段,我想在标签内使用 HTML 代码,仅此而已。
Field labels in Views are assuming plain-text input and they are probably using check_plain() to encode special characters (didn't actually look at Views back-end).
How can HTML code be used inside labels?
Edit: I thought my question is clear. I don't want to rewrite fields, I want to use HTML code inside a label, that's all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我想通了。虽然您无法在视图 UI 上的标签内使用 HTML 输入,但您可以在样式输出模板内自定义标签。
例如,对于使用表格样式输出的“示例”视图,您可以自定义
views-view-table--example.tpl.php
并使用如下代码:I figured it out. While you can't use HTML input inside labels on the Views UI, you can customize a label inside a style output template.
e.g. for an "example" view that uses a table style output you would customize
views-view-table--example.tpl.php
and use a code like:另一个解决方案是为特定视图格式添加新的处理函数,并在该预处理函数中进行更改。
例子:
Another solution is adding a new process function for the particular view format, and make your changes in that preprocess function.
Example:
您可以对该字段使用
重写输出
选项。you could use
Rewrite output
option for that field.这与“strip html”无关,忽略它。
出于这个原因,视图字段具有“重写”功能。这样您就可以重写 html 输出,然后使用令牌重新插入动态元素。
因此,要重写字段,将其包装在 h1 标记中,您可能会执行以下操作...
编辑您的字段。在 D7 Views 3 中,您会在“重写结果”下看到一个切换部分。打开它并勾选“重写该字段的输出”。
在其下方的大框中输入:
就这样。简单的。当视图被重新渲染时,您的标题文本将被包裹在 h1 标签中。
您可以在重写规则中使用的标记在下方名为“替换模式”的切换中列出 - 它们根据字段的类型而变化。
This has got nothing to do with 'strip html', ignore that.
Views fields have 'rewrite' functions in them for just this reason. So that you rewrite the html output and then use a token to reinsert the dynamic element.
So to rewrite field, wrapping it in an h1 tag you might do something like this...
Edit your field. In D7 Views 3 you see a toggle section under 'Rewrite Results'. Open this and tick 'Rewrite the output of this field'.
In the big box under it type:
And that's it. Simple. When the view is redended your title text will be wrapped in h1 tags.
The tokens you can use in the rewrite rule are listed in the toggle called 'replacement patterns' a bit lower down - they change depending on what type of field it is.
视图 7.x-3.3
我编辑模块 theme/theme.inc 文件:删除 check_plain
Views 7.x-3.3
I edit the module theme/theme.inc file: remove the check_plain