只渲染来自Drupal 7自定义字段的网址

问题描述:

我很难在node--My_Content_Type_Node.tpl.php的自定义节点显示中为自定义字段渲染url(无标题,div标记等)。我一直在尝试走路线概述here,但一直都很艰难。这里是我的具体情况:只渲染来自Drupal 7自定义字段的网址

我的自定义字段是一个分类术语参考论坛,与taxonomy_forums

我一直在尝试使用(与微妙的变化)以下的机器名,没有成功:

$url = render($node->taxonomy_forums[$node->language][0]['url']); 

本质上,我试图将内容绑定到特定的预创建论坛进行评论,并创建一个链接。

我可以使用以下显示的默认布局(链接,标题,标记),但没有运气分隔条件吧:

$Forum = render($content['taxonomy_forums']); 

任何帮助非常感谢,这是我的第一篇文章在这里,所以请让我知道是否需要更多细节。

谢谢!

更新:Recaiving为VAR转储如下:

array(1) { ["und"]=> array(1) { [0]=> array(2) { ["tid"]=> string(1) "5" ["taxonomy_term"]=> object(stdClass)#81 (8) { ["tid"]=> string(1) "5" ["vid"]=> string(1) "2" ["name"]=> string(13) "Total Rewards" ["description"]=> string(167) "Use this space to ask questions, make comments, or start a conversation with Grameen Foundation and other site users related to assessing your total rewards practices." ["format"]=> NULL ["weight"]=> string(1) "4" ["vocabulary_machine_name"]=> string(6) "forums" ["rdf_mapping"]=> array(5) { ["rdftype"]=> array(2) { [0]=> string(14) "sioc:Container" [1]=> string(10) "sioc:Forum" } ["name"]=> array(1) { ["predicates"]=> array(2) { [0]=> string(10) "rdfs:label" [1]=> string(14) "skos:prefLabel" } } ["description"]=> array(1) { ["predicates"]=> array(1) { [0]=> string(15) "skos:definition" } } ["vid"]=> array(2) { ["predicates"]=> array(1) { [0]=> string(13) "skos:inScheme" } ["type"]=> string(3) "rel" } ["parent"]=> array(2) { ["predicates"]=> array(1) { [0]=> string(12) "skos:broader" } ["type"]=> string(3) "rel" } } } } } }

+0

您是否收到任何错误,或者$ url在输出时是否不包含数据?你做了一个var_dump($ node-> taxonomy_forums);'看看那里有什么? – 2013-03-26 22:36:04

+0

特里,我收到以下编辑的代码,已在上面进行了编辑。 – 2013-04-01 13:54:04

要渲染只是一个网址,你可以检查此功能url()。您可以指定是否需要绝对或相对网址。所以,如果你需要绝对的URL,然后代码可以是这样的:

$url = url($node->taxonomy_forums[$node->language][0]['url'], array('absolute' => TRUE)); 

而你需要确保$node->taxonomy_forums[$node->language][0]['url']是正确的阵列结构。你可以通过devel函数dsm($node->taxonomy_forums)来检查它。只要确保安装了devel模块。

+0

谢谢Vadim!你的使用devel的建议帮助我弄明白了,再次感谢。 – 2013-04-01 17:53:12