Showing available variables in a theme and making new ones
Together these will get us there (creating the variable) but I have the feeling it already exists-- how do I see it?
<?php
function _phptemplate_variables($hook, $vars) {
switch ($hook) {
case 'page':
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
$vars['content_is_node'] = TRUE;
}
break;
}
return $vars;
}
?>
<?php
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
if ((arg(0) == 'admin')) {
$vars['template_file'] = 'page-admin';
}
break;
}
return $vars;
}
?>
Answer:
What Functions Are Available In A Drupal PHPTemplate Theme?
http://baheyeldin.com/drupal/what-functions-are-available-in-a-drupal-phptemplate-theme.html
Submitted by Khalid on Mon, 2005/12/05 - 17:55.
Darrel O'Pry posted this gem on the Drupal Themes mailing list, and it deserves to be publicized.
Paste this in your page.tpl.php below the tag, to see what functions are available for you, the theme developer.
<?php
$functions = get_defined_functions();
foreach($functions['user'] as $function) :
print "<li>$function</li>";
endforeach;
?>
Similarly, one can use the get_defined_vars() and get_defined_constants() to see what variables are available.
Now, use your imagination and build nice themes ...
need to look more into get_defined_vars
just a print_r is the best way to use it
That's cute. The is_admin variable doesn't actually work. Ahh-- that's a variable set by the Zen theme which tells you if the current user is an admin (not whether the section being viewed is an administration section)
Also on the Zen theme, adding this to the _phptemplate_variables function does the job:
if (arg(0)=='admin') {
$body_classes[] = 'admin';
}
<?php
$variables = get_defined_vars();
print '<pre>';
print_r($variables);
print '</pre>';
?>
/* // not all this silliness \
foreach($variables as $key->$variable) :
if (!is_array($variable)) {
print "<li>$key -> $variable</li>";
}
else {
print '<li><pre>';
print_r($variable);
print '</pre></li>';
}
endforeach;
?>
*/
More:
Making additional variables available to your templates
http://drupal.org/node/16383
displaying all variables available and debugging your advanced custom login form
http://drupal.org/node/154248
Comments
Now, use your imagination
Now, use your imagination and build nice themes ...
Post new comment