How to print node taxonomy in a block?

I would like to print the taxonomic terms (from the field field_tags) in a block on the node view page (in the Zen subtopic).

So what I did.

template.php

function michal_preprocess_block(&$vars, $hook) {
 if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
   $node = node_load(arg(1));
   $vars['node'] = $node;
   $vars['node_field_tags'] = $node->field_tags;
   $vars['node_content_field_tags'] = $node->content['field_tags'];
 }
}

However, when I try to type it in block.tpl.php, none of these two variables will deduce the terms of taxonomy from the field.

print render($node_content_field_tags);
print render($node_field_tags);

Do you know the Drupal function to display a taxonomy term field?


EDIT 1/13/2011 00:21 AM

As far as I understood (from this , this and which ), this code should look more / less like this

 $node = node_load(arg(1));
 $node_view($node) // Generates an array for rendering a node, see http://api.drupal.org/api/drupal/modules--node--node.module/function/node_view/7
 $vars['node'] = $node;

and then to block.tpl.php:

render($node->content['field_tags']);

However, the contents of $ node → is null.

Do you know what I am missing?

+3
source share
4 answers

, :

mytheme_preprocess_block() template.php *

$node_content = node_view(node_load(arg(1)));
$vars['node_content'] = $node_content;

.

block.tpl.php

print render($node_content['field_tags']);
+1

, , :

if ($node = menu_get_object()) {
  $vars['node_field_tags'] = field_view_field('node', $node, 'field_tags', 'full');
}

:

print render($node_field_tags);
+2

, , . . , render() $node->field_tags, $node->content['field_tags'].

, devel Drupal 7 .

+1

You can also check the CCK Blocks module . It creates a sidebar block that appears next to each node (if it has content), and adds this block to the list of rendering assignments for each field, just like teaser and full and rss.

It may not have all the controls you are looking for, but it may be a good place to start.

+1
source

Source: https://habr.com/ru/post/1784830/


All Articles