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

kscheirer’s picture

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!

jamesh123’s picture

Based on your reply i tried

<?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['name']?></li>
    <?php endforeach; ?>
    <img src="<?php print ("$base_path$directory") ?>/graphics/menu_right_corner.gif" width="25" height="17" class="left"/>
	</ul>
  <?php endif; ?> 

and now nothing gets output.

Thanks

James

kscheirer’s picture

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.

<?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 echo '<pre>'  . print_r($link, 1) . '</pre>' ?></li>
    <?php endforeach; ?>
    <img src="<?php print ("$base_path$directory") ?>/graphics/menu_right_corner.gif" width="25" height="17" class="left"/>
</ul>
  <?php endif; ?> 

hope thats clearer