Drupal 7 Views - 如何在字段标签内使用 HTML 代码?

发布于 2024-12-19 18:41:03 字数 256 浏览 4 评论 0原文

视图中的字段标签假设纯文本输入,并且它们可能使用 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

江湖彼岸 2024-12-26 18:41:03

我想通了。虽然您无法在视图 UI 上的标签内使用 HTML 输入,但您可以在样式输出模板内自定义标签。

例如,对于使用表格样式输出的“示例”视图,您可以自定义 views-view-table--example.tpl.php 并使用如下代码:

//custom label for title field
$header['title'] = '<strong>Foo</strong> bar';

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:

//custom label for title field
$header['title'] = '<strong>Foo</strong> bar';
開玄 2024-12-26 18:41:03

另一个解决方案是为特定视图格式添加新的处理函数,并在该预处理函数中进行更改。

例子:

/**
 * Implements hook_theme_registry_alter().
 */
function example_theme_registry_alter (&$theme_registery) {
    $theme_registery['views_view_table']['preprocess functions'][] = 'example_alter_table_header';
}

function example_alter_table_header(&$vars) {
  $view = $vars['view'];
  if ($view->name == 'my_view') {
    $vars['header']['field_some_title'] = 'HELLO<br/>WORLD';
  }

}

Another solution is adding a new process function for the particular view format, and make your changes in that preprocess function.

Example:

/**
 * Implements hook_theme_registry_alter().
 */
function example_theme_registry_alter (&$theme_registery) {
    $theme_registery['views_view_table']['preprocess functions'][] = 'example_alter_table_header';
}

function example_alter_table_header(&$vars) {
  $view = $vars['view'];
  if ($view->name == 'my_view') {
    $vars['header']['field_some_title'] = 'HELLO<br/>WORLD';
  }

}
待"谢繁草 2024-12-26 18:41:03

您可以对该字段使用重写输出选项。

you could use Rewrite output option for that field.

默嘫て 2024-12-26 18:41:03

这与“strip html”无关,忽略它。

出于这个原因,视图字段具有“重写”功能。这样您就可以重写 html 输出,然后使用令牌重新插入动态元素。

因此,要重写字段,将其包装在 h1 标记中,您可能会执行以下操作...

编辑您的字段。在 D7 Views 3 中,您会在“重写结果”下看到一个切换部分。打开它并勾选“重写该字段的输出”。

在其下方的大框中输入:

<h1>[title]</h1>

就这样。简单的。当视图被重新渲染时,您的标题文本将被包裹在 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:

<h1>[title]</h1>

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.

关于从前 2024-12-26 18:41:03

视图 7.x-3.3

views/theme/theme.inc:269:      $object->label = check_plain($view->field[$id]->label());

views/theme/theme.inc:498:      $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');

我编辑模块 theme/theme.inc 文件:删除 check_plain

Views 7.x-3.3

views/theme/theme.inc:269:      $object->label = check_plain($view->field[$id]->label());

views/theme/theme.inc:498:      $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');

I edit the module theme/theme.inc file: remove the check_plain

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文