print $links??
madjoe - September 13, 2007 - 15:49
| Project: | Node As Block |
| Version: | 5.x-1.1 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
How can I print entire $links inside of nodeasablock.tpl.php, that is related to a certain nid?

#1
This code doesn't return anything, but when I view it as a node, then $links are displayed:
<?phpglobal $links;
echo $links;
?>
#2
Try theme('links', $node->links);
#3
It returns a warning: Invalid argument supplied for foreach() in /DRUPAL_PATH/themes/MY_THEME/links.tpl.php on line 12.
links.tpl.php:
<?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++;
}
?>
#4
Try pre-pending this before the call to theme('links', $node->links):
<?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);
}
?>
This is taken from node_view:
http://api.drupal.org/api/function/node_view/5
#5
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>