Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By EulerFan on
I am having problems working with my theme functions. Basically, I don't know what variables are being passed or the structure of the array under theme_*name*()
How should I refer to my passed array 'Nut_Label' in theme_nut_label?
function foodlib_view($node, $view_mode) {
$node->content = array(
'description' => array(
'#type' => 'item',
'#title' => t($node->foodlib_name)
),
'food_description' => array(
'#markup' => t($node->foodlib_shrt_desc),
'#weight' => 2
),
'NDB_NO' => array(
'#markup' => 'BLANCO' /*$node->foodlib_NDB_NO*/,
'#weight' => 3
),
'foodlib_Energ_Kcal' => array(
'#markup' => t($node->foodlib_Energ_Kcal),
'#weight' => 4
),
'foodlib_Carbohydrt' => array(
'#markup' => t($node->foodlib_Carbohydrt),
'#weight' => 5
),
'Nut_Label' => array(
'#weight' => 6,
'#theme' => 'nut_label',
'Nutrition Facts' => array('Nutrition Facts')
)
);
return $node;
}
function foodlib_theme($existing, $type, $theme, $path) {
return array(
'nut_label' => array(
'render element' => 'Nut_Label'
)
);
}
function theme_nut_label($hook, $variables = array()) {
$content = $variables;
$large_font = '<span class="large-font">';
$medium_font = '<span class="medium-font">';
$small_font = '<span class="small-font">';
// The div of the box
$output = '<div class="nut-label">';
// Our Title
$output .= '<div class="'.$content['Nutrition Facts'].'">'.$content['Nutrition Facts'].'</div>';
$output .= </div>
return $output;
}
The example supplied said to call $variables['element'] but that did not work.
Comments
Follow this Example
You have not passed variable to theme function.
Follow this Example . Will give you complete overview.
Kamlesh Patidar
This:<?php $content =
This:
Should be this:
function
Still no luck, I changed
and changed
Now it doesn't say undefined index, but it won't print anything. The markup prints
<div class=""></div>
The array being passed to my
The array being passed to my theme function has nothing in it. I tried to print it, $variables is a completely blank array.
I only told you to change one
I only told you to change one thing, why did you change your hook_theme() implementation?