How can I print entire $links inside of nodeasablock.tpl.php, that is related to a certain nid?

Comments

jazzitup’s picture

This code doesn't return anything, but when I view it as a node, then $links are displayed:

 global $links;
echo $links; 
mfredrickson’s picture

Try theme('links', $node->links);

jazzitup’s picture

It returns a warning: Invalid argument supplied for foreach() in /DRUPAL_PATH/themes/MY_THEME/links.tpl.php on line 12.

links.tpl.php:

/**
* to change the delimiter, just modify the $delimiter value
* Add in other fixed links to the link array by adding something like
* $links[] = l('link text', 'link path');
*
*/

$delimiter = " | ";
$link_count = count($links);
$current = 1;
foreach ( $links as $lnk ) {
	($lnk['href']) ? print(l($lnk['title'], $lnk['href'], $lnk['attributes'])) : print(t($lnk['title']));
        // Only print the delimiter if not the last link
    if ( $current < $link_count ) {
        print $delimiter;
    }
    $current++;
}
mfredrickson’s picture

Try pre-pending this before the call to theme('links', $node->links):

$node->links = module_invoke_all('link', 'node', $node, $teaser);

    foreach (module_implements('link_alter') AS $module) {
      $function = $module .'_link_alter';
      $function($node, $node->links);
    }

This is taken from node_view:

http://api.drupal.org/api/function/node_view/5

jazzitup’s picture

Um.. no, still nothing. This time it shows the content of $links, but not associated to a node itself. For example, my node has a read/write property for comments and it should be visible inside of $links as "comment", but I can't see it this way. Am I missing something?

nodeasblock.tpl.php:

<div <?php {
  echo 'id="block-nodeasblock-'.$node->nid.'"';
  echo ' class="block block-nodeasblock-',$node->nid,'"';
} ?>>

  <?php
   $node->links = module_invoke_all('link', 'node', $node, $teaser);

     foreach (module_implements('link_alter') AS $module) {
       $function = $module .'_link_alter';
       $function($node, $node->links);
    }
   ?>

  <div class="content">
    <span class="small"><?php echo $node->teaser; ?></span>
  </div>
  <div class="links"><?php echo theme('links', $node->links); ?></div>
</div>