问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/5835392/customize-a-field-output