Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By jamesh123 on
hi,
I'm in the process of developing my first drupal theme and am having some problems getting the primary navigation to display properly. Instead of displaying the correct links several items containing the work 'Array' are displayed instead. The code i am using is shown below.
<div id="navcontainer">
<?php if (is_array($primary_links)) : ?>
<ul id="navlist">
<img src="<?php print ("$base_path$directory") ?>/graphics/menu_left_corner.gif" width="34" height="17" class="left"/>
<?php foreach ($primary_links as $link): ?>
<li><?php print $link?></li>
<?php endforeach; ?>
<img src="<?php print ("$base_path$directory") ?>/graphics/menu_right_corner.gif" width="25" height="17" class="left"/>
</ul>
<?php endif; ?>
</div>
The url is http://slx.hacks.no/
Thanks in advance,
James
Comments
could be
that the $link elements are also arrays.
so when you do "print $link", it doesn't know how to display, and just prints the word Array.
You probably want to output a specific element of the array, like $link['name'].
You can use print_r($link, TRUE) to output the entire $link element, and see whats inside if you're unsure
hope that helps!
results of $link['name']
Based on your reply i tried
and now nothing gets output.
Thanks
James
sorry
I think you took my reply too literally.
$link['name'] was just an example. I have no knowledge of what is inside your $link variable.
But we do know that the $link variable is an array. The easiest way to find out whats inside
is by printing the entire contents of the array, using print_r(),
and then you can hopefully see the element you want to display.
try this, and post the result back here if it's not clear. You may have to do a 'view source' to get a better look at the output.
hope thats clearer