drupal7 覆写node-type.tpl.php获取字段值的两种方式

2023-05-19,,

字段的机读名称为:field_publication_date

 <!-- 下面两种方式都可以获取node字段的值-->
出版时间:
<?php print date('Y-m-d',$node->field_printing_date['und'][0]['value'])?>

  <?php print date('Y-m-d',$field_printing_date[0]['value'])?>

上面两种方式都可以,但是第二种比较简洁。效果如下:

但是,如果打算为该字段输出定制模板的话,还是直接使用drupal核心自带的render函数,并以

render($content['field_publication_date'])

的方式输出字段内容。

其实时间的输出格式,应该在内容类型的“管理显示”页面进行设置的,这里仅仅是作为获取值的例子进行举例来用的。

drupal7 覆写node-type.tpl.php获取字段值的两种方式的相关教程结束。

《drupal7 覆写node-type.tpl.php获取字段值的两种方式.doc》

下载本文的Word格式文档,以方便收藏与打印。