1

I have a custom module which initiates the theme hook - passing the $node object as an argument:

theme('my_widget', array($node)); 
function my_module_theme() {
  return array(
    'my_widget' => array(
      'template' => 'my_widget',
      'variables' => array('node' => array($node)),
    ),
  );
}

However, in the 'my-widget' template file, I need to pick up the $node variable. But doing a dpm() on $node returns Null.. - think I may be setting the variable incorrectly, but not sure what's going on. Cheers

5

The correct code is the following one.

  • Theme call

    theme('my_widget', array('node' => $node)); 
    
  • Theme declaration

    function my_module_theme() {
      return array(
        'my_widget' => array(
          'template' => 'my_widget',
          // This array contains the default values.
          // You should not use a PHP variable.
          'variables' => array('node' => NULL),
        ),
      );
    }
    
  • how to print this variable in tpl file (ie) in my_widget.tpl.php – user3386779 Sep 4 '17 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.