清理视图模板中的字段输出
我正在尝试获得干净的字段输出以获得语义代码。 在视图模块生成的默认模板中,输出字段的代码片段是:
<?php print $field->content; ?>
但是随着字段的值生成了很多标记。 有没有办法直接获取字段值?
我正在使用 Drupal 7,看起来老方法:
$fields['field_name']->content;
不再起作用了。
预先感谢您的帮助。
I'm trying to get clean output of fields in order to obtain semantic code.
In the default template generated by the Views module the snippet which outputs the field is:
<?php print $field->content; ?>
But a lot of markup is generated along with the value of the field.
Is there a way to get the field value directly?
I'm using Drupal 7, It seems like the old method:
$fields['field_name']->content;
is not functioning anymore.
Thank you in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
语义视图就是答案。但 Drupal 7 仍处于开发阶段。
Semantic views is the answer. But it is still in dev for Drupal 7.
语义视图是一个很棒的模块,可以很好地控制视图输出标记。但我意识到我的问题与字段标记有关。
我找到了一个视频教程。它对我帮助很大,希望也能帮助其他人。
主题字段视频教程。
Semantic Views is a great module which gives a great control over the views output markup. But I realized that my problem was related to the field markup.
I found a video tutorial. It helped me a lot and hope could help others too.
Theming Fields video tutorial.
要自定义视图的输出,您需要编辑适当的视图模板。您可以在modules/views/theme目录中找到模板。将您需要的复制到主题目录中并根据您的喜好进行编辑。您可以为不同的视图定制模板,查看视图选项中的“高级->主题:信息”以查看视图模块识别哪些文件名。您可能需要原始视图模板才能使自定义模板发挥作用。添加新的自定义视图模板或删除它们后,请务必按“主题:信息”中的“重新扫描模板文件”按钮。
To customize output of Views you'll need to edit appropriate Views templates. You can find templates in modules/views/theme directory. Copy the ones you need to your theme directory and edit to your liking. You can have custom templates for different views, check out "Advanced->Theme: Information" in View options to see what file names are recognized by Views module. You might need original view template for customized template to work. Be sure to press "Rescan template files" button in "Theme: Information" after adding new custom view templates or removing them.