Drupal 7:查看节点时隐藏带有空字段的标签
在查看特定内容类型的实际节点时,如何隐藏具有空字段的标签?
我真的很感谢任何人的帮助,感谢您的宝贵时间。
How do I hide labels that have empty fields when viewing the actual node of a certain content type?
I'd really appreciate anyone's help, thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实现此目的的另一种方法是使用适用于该内容类型的所有节点的自定义模板文件。
确保 node.tpl.php< /a> 首先存在于您的
sites/all/themes/[mytheme]
目录中。在调用其他自定义模板之前,该模板必须存在。复制您的node.tpl.php并将其命名为
node--[contenttype].tpl.php
(不带括号)。如果您启用了 Devel 模块,则可以抛出
dpm($content); 进入文件以找出您要隐藏的字段的名称。或者您可以查看内容类型本身。
获得字段名称后,您现在可以在
print render($content);
语句之前插入此代码:清除缓存,并且仅当存储了值时才会显示您的字段。
Another way you could achieve this is by using a custom template file that would apply to all nodes of that content type.
Make sure that node.tpl.php exists in your
sites/all/themes/[mytheme]
directory first. This template must exist before other custom templates can be called.Make a copy of your node.tpl.php and name it
node--[contenttype].tpl.php
(without the brackets).If you have the Devel module enabled, you can throw a
dpm($content);
into the file to find out the name of the field you are trying to hide. Or you could look at the content type itself.Once you have the name of the field, you can now insert this code before the
print render($content);
statement:Clear the cache, and your field will only appear if there is a value stored.
默认情况下,空字段的标签是隐藏的,也许该字段中仍然存在“不间断空格”或其他剩余内容?
您必须检查出现问题的现有节点与未触及特定字段的新节点之间的差异。
设置隐藏在 nl/admin/struct/types/manage/selected_content_type/display 中的不需要的标签显示
By default, the labels of empty fields are hidden, maybe there's still a 'non breaking space' or some other leftover in the field?
You have to check the difference between an existing node where the problem occurs and a new node where you don't touch the particular field.
Set unwanted labels display hidden in nl/admin/structure/types/manage/selected_content_type/display
我想纠正第一个答案。在node.tpl.php中,我们应该检查#markup而不是字段数组:
而不是
I would like to correct first answer. In node.tpl.php we should check #markup instead of field array:
instead of
如果内容类型有很多循环字段,这对我有用:
If the content type has a lot of fields looping this worked for me: