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

kamleshpatidar’s picture

You have not passed variable to theme function.
Follow this Example . Will give you complete overview.

Kamlesh Patidar

Jaypan’s picture

This:

	$content = $variables;

Should be this:

	$content = $variables['Nut_Label'];

The Drupal organization has shut down discussion on improvement of the forums: https://www.drupal.org/node/2536122

It's time to start a new forum somewhere else. The Drupal organization does not care about the forums.

EulerFan’s picture

Still no luck, I changed

function foodlib_theme($existing, $type, $theme, $path) {

  return array(
    'nutri_label' => array(
		'variables' => array('Nut_Label' => NULL),
		'render element' => 'Nut_Label' 
		)
		);
		}

and changed

$content = $variables['Nut_Label']

Now it doesn't say undefined index, but it won't print anything. The markup prints

<div class=""></div>

EulerFan’s picture

The array being passed to my theme function has nothing in it. I tried to print it, $variables is a completely blank array.

Jaypan’s picture

I only told you to change one thing, why did you change your hook_theme() implementation?

The Drupal organization has shut down discussion on improvement of the forums: https://www.drupal.org/node/2536122

It's time to start a new forum somewhere else. The Drupal organization does not care about the forums.