自定义字段输出 [英] Customize a field output

查看:119
本文介绍了自定义字段输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为field_enroll_link的字段。我想删除所有周围的div,并打印字段内容(它将进入锚标签的href)。我创建了文件field-field_enroll_link-course.tpl.php和field-field-enroll-link-course.tpl.php,并将其放入我的模板文件夹中。它只包含<?php print render($ item); ?> ,但是当我清除缓存,甚至切换主题时,我仍然会收到所有周围的div和标记。如何覆盖Drupal 7中的field.tpl.php?

解决方案

在您的主题的template.php文件中定义此函数,清除缓存。我假设你已经安装了devel模块。

  function your-theme_name_field($ variables){
dsm($ variables ['items'] [0] '#markup']);
return;

}



您将能够访问您要查找的值。


I have a field named "field_enroll_link." I want to remove all the surrounding divs and just print the field content (it will go into the href of an anchor tag). I created the files "field--field_enroll_link-course.tpl.php" and "field--field-enroll-link-course.tpl.php," and put it into my template folder. It just contained <?php print render($item); ?>, but when I cleared the cached and even switched the themes, I'm still getting all the surrounding divs and markups. How do I override the field.tpl.php in Drupal 7?

解决方案

In your theme's template.php file define this function and clear the cache. I am assuming you have devel module installed.

function your-theme_name_field($variables){
dsm($variables['items'][0]['#markup']);
return ;

}

You will be able to access the value you are looking for.

这篇关于自定义字段输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆