I'm at my wits end with Drupal 6 right now, and I'm hoping a second pair of eyes might be able to point out some syntax sublety I was missing earlier this morning.
Lets say I have a theme called my_theme
.
This is a theme that subthemes from Ginkgo, a theme which which in turn subthemes from Rubik, whith in tun subthemes from Tao, a fairly common CSS reset theme.
I'm trying to understand how to declare my own theme functions, so I can clean up the mark up on a fee page I'm workign on for site.
Now my understanding of theming is along the lines of ' if register a theming function with hook_theme, passing it into an array, with the function's name, you'be able to call it in future with theme_function_name from within your theme.
For example, if have a module called my
, I'd immplent the hook_theme
like below, defining the name of the function, and defining which
argument should be passed into it:
<?php
function my_theme() {
$items = array();
$items['randomtext'] = array('arguments' => array('element' => NULL));
$items['button_links'] = array('arguments' => array( '$links' => NULL, '$attributes' => NULL));
return $items;
};
Now I have the functions registered, I just need to implement them like this somewhat contrived example:
function theme_randomtext($element) {
$output = ' <h1>This is some very random text with' . ' this text concatenated: ' . $element . '</h1>';
return $output;
}
I can now use this new function by calling
<php
print theme('randomtext', 'some arbitrary words')
?>
And expect the following content to be returned:
<h1>This is some very random text with this text concatenated: some arbitrary words</h1>
I'm getting nada.
And I don't know why. When I look at the theme registry, I see my
function listed as my_randomtext
- I've tried calling both of these
options, in case I should have been adding the theme prefix:
theme('my_randomtext', 'getting desparate');
theme('randomtext', 'really losing my rag now');
Still no luck.
Why might these theme functions not be working? And what advantage does this give you over simply declaring a function like so in a theme?
function manual_random_text($element) {
$output = ' <h1>This is gives me everything I aleady need,
'without relying on the weird themeing sytem. It's perfect for' . $element . '</h1>';
return $output;
}