仅渲染Drupal 7自定义字段中的URL

时间:2013-03-26 22:29:24

标签: php drupal drupal-7

我很难在node--My_Content_Type_Node.tpl.php的自定义节点显示中为自定义字段呈现网址(无标题,div标记等)。我一直试图走上here概述的路线,但一直很艰难。以下是我的具体内容:

我的自定义字段是对论坛的分类术语引用,其机器名称为taxonomy_forums

我一直试图使用以下(以及微妙的变化),但没有成功:

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

基本上,我正在尝试将内容绑定到特定的预先创建的论坛以进行评论,并创建指向它的链接。

我可以使用以下内容显示默认布局(链接,标题,标记),但没有运气将其分开:

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

任何帮助都非常感谢,这是我在这里的第一篇文章,所以如果需要更多细节,请告诉我。

谢谢!

更新:为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" } } } } } }

1 个答案:

答案 0 :(得分:1)

要仅呈现网址,您可以检查此功能url()。您可以指定是否需要绝对或相对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模块。