Hello everyone!
I've followed the node_example.module tutorial and the Creating modules tutorial to create a module. It's a roster of characters for an online game. I have the roster working, and it lists the characters correctly. Now when I click on the character name, I'd like to show a profile of the character, with all the information.
In the roster_node_info hook, I've set has_title and has_body to FALSE for now. In the roster_view hook, I've done things as described in the node_example.module:
function roster_view($node, $teaser = FALSE, $page = FALSE) {
$node = node_prepare($node, $teaser);
$node->content['myfield'] = array(
'#value' => theme('roster_character', $node),
'#weight' => 1,
);
return $node;
}
Therefore I have a custom theme function like this:
function theme_roster_character($node) {
$output = '<div>';
$output .= t('The name of the character is %first_name %last_name.', array('%first_name' => check_plain($node->first_name), '%last_name' => check_plain($node->last_name)));
$output .= '</div>';
return $output;
}
Now what I'd like to do is to use the same procedure as in the roster page: use a template and the PHPTemplate engine. So, I've tried this:
function roster_theme() {
return array(
'roster' => array(
'template' => 'roster',
'arguments' => array('roster' => NULL, 'chars_per_page' => NULL),
),
'roster_character' => array(
'template' => 'roster-character',
'arguments' => array('node' => NULL),
),
);
}
And I've created the roster-character.tpl.php template with some basic output. The thing is that it does not work: it always goes for the theme_roster_character instead of the template, and I don't know how to tell it to act the same way as the roster page (see the other entry of the array in the roster_theme hook.
Any hints?
Thanks in advance.
Comments
It was correct.
Hmmm.... it seems my code was correct, but something was preventing the changes from showing. Very weird, but the thing is that I decided to do some theme searching, tried about a dozen of them, and then I hit the "details" button to go to the node render page, and voilà, it was there!
Time to improve the default character template I was working with now...
Cheers!