API page: http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_lin...

The documentation of use is not clear without an example. The function does not work as expected and does not return errors when tested with:

function MyModule_test()
{
	$linklist = array(
  'item1' => array( 'title' => '1st Item', 'href' => 'one' ),
  'item2' => array( 'title' => '2nd Item', 'href' => 'two' ),
  'item3' => array( 'title' => '3rd Item'),
             array( 'title' => '4th Item', 'href' => 'four' ),
  'item5' => '',
  'item6' => array( 'title' => '6th Item', 'href' => 'six' )
);
$output = theme('links', $linklist);
return $output; 
}   	

Comments

jhodgdon’s picture

Category: bug » support
Status: Active » Fixed

You didn't follow the documentation. There is one argument $variables, which is an array with required element 'links', and optional 'heading' and 'attributes'. You passed in an array with elements 'item1', 'item2', etc.

carlmcdade’s picture

As I said with the unclear wording and the syntax needed the documentation needs to have a working example. You'll never be able to explain this otherwise.

This works:

function inventory_test()
{
  $linklist = array(
  'item1' => array( 'title' => '1st Item', 'href' => 'one' ),
  'item2' => array( 'title' => '2nd Item', 'href' => 'two' ),
  'item3' => array( 'title' => '3rd Item'),
             array( 'title' => '4th Item', 'href' => 'four' ),
  'item5' => '',
  'item6' => array( 'title' => '6th Item', 'href' => 'six' )
);
	
 print theme('links', array(
  'links' => $linklist,
  'attributes' => array('class' => array('links', 'inline'))));
}   
$variables: An associative array containing:

Should be something like:

$variables: An associative array with keys of (links, ...) and each value is an array containing:...

And even that begins to fall short if not broken up with code examples.

jhodgdon’s picture

We don't generally add examples to the documentation itself -- there are plenty of examples of calls to theme('links') in the Drupal Core code already.

Feel free to add your example as a comment on that page, to aid others having the same difficulty.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.