Drupal 7:将自定义内容类型字段调入页面tpl

问题描述:

我正在使用Drupal 7网站。我需要一些页面的自定义布局。所以我创建了页面 - customContentTypeName.tpl.php文件,它的地址完美。Drupal 7:将自定义内容类型字段调入页面tpl

问题是,我需要在页面tpl中显示一些字段。下面的代码在节点tpl中工作正常,但页面tpl:/

<?php print $content['field_images']['#items']['0']['filename']; ?>" /> 

如何在页面tpl中调用自定义字段?

鉴赏帮助!非常感谢!!


** SORTED **

与自定义字段编辑......这里是视频教程:http://lin-clark.com/blog/intro-drupal-7-theming-fields-and-nodes-templates#comment-54

在7改变的结构,该场是由语言第一键控( “und”默认意味着“undefined”),那么你可以按照这个例子:

// Array of Image values 
$images = $node->field_images['und']; 

//If you don't know the language, the value is stored in: 
$node->language 


// First image 
$image = $images[0]; 



// If you need informations about the file itself (e.g. image resolution): 
image_get_info($image["filename"]); 


// If you want to access the image, use the URI instead of the filename ! 
$public_filename = file_create_url($image["uri"]); 


// Either output the IMG tag directly, 
$html = '<img src="'.$public_filename.'"/>'; 

// either use the built-in theme function. 
$html = theme(
    "image", 
    array(
     "path" => $public_filename, 
     "title" => $image["title"] 
    ) 
); 

请注意使用uri而不是filename用于将图像嵌入到页面中,因为​​(为了更容易与CDN服务集成)。

+0

另请注意,在前导模式下(例如,列出了许多节点的分类术语页面),默认情况下变量$ node中不提供此类字段。 – wildpeaks 2011-03-04 16:52:23

+0

顺便说一句,StackOverflow的Drupal专用区域将在几天内公开测试:http://drupal.stackexchange.com – wildpeaks 2011-03-04 16:54:59

对于page.tpl.php中 如果访问节点直接可以使用$节点变量

$node['field_images']['und'][0]['filename'] 

否则使用$ page变量。

$page['content']['system_main']['nodes'][1]['field_images']['#items'][0]['filename']; 

但记住一个页面变量,你可能有多个节点。

在主题开发人员的drupal中有2个有用的模块: Devel和Theme_developer Devel模块提供了一个名为dsm()的函数。使用dsm的 您可以识别如何将元素存储在不同的对象中。 像节点或... 例如,您可以使用此语句:dsm($ node) 页面中任何节点的结构将显示在消息框中。 您可以在代码中输入语句。