1

I have defined a function to return an array and need to pass this array as a parameter to a template (node--contenttype.tpl.php).

function mymodule_preprocess_page(&$variables) {{
  $variables['tdata'] = $myArray;
}

In node--contenttype.tpl.php

print $tdata;

I tried to call the variable $tdata, but the error shows

Notice: Undefined variable: tdata in include()...

The same error happens if I define a variable in template.php and call from node--contenttype.tpl.php.

random
  • 9,774
  • 10
  • 66
  • 83
user1480765
  • 177
  • 3
  • 11
  • It seems like this post might be helpful: [Where to declare variables common to different include files in a module - Drupal](http://stackoverflow.com/a/6042617/751619) – codewaggle Jun 26 '12 at 06:09
  • Could you show us the code in your template file where you're trying to access the variable? – Boriana Ditcheva Jun 26 '12 at 20:49
  • What's with the double brace `{{` on the function line? That's not valid syntax. – Spudley Jun 26 '12 at 21:42

1 Answers1

1

Oops... I think I see your problem now.

You should be using hook_preprocess_node(), not hook_preprocess_page() if you want your variables to be available in your node template files.

Make sure you clear cache after you make the change too!

Let us know if that fixed your issue...

Boriana Ditcheva
  • 1,995
  • 15
  • 26