I have an array printing in module file. I want to theme that array data,so I am not getting how can I get that array data in template file. I don't want to create theme function and all. is there any inline solution to pass from module to template. My code is like below.

$data['listfiles'] = array(
    '#theme' => 'table',
    '#header' => $filesheader,
    '#rows' => $rows,
    '#empty' => t('No content available.'),

  return $data; 

I want to pass $data variable to the template file, so that I can theme the data.Thanks in advance for any suggestions.


In form.

 * Implements hook_theme().
function YOURMODULE_theme() {
  $themes = array(
    'example' => array(
      'template' => 'templates/example',
      'arguments' => array('data' => NULL),
  return $themes;

after this you can pass your data as

return theme('example', array('data' => $data));

Refer this

And if want to use preprocess to alter data, see hook_preprocess_HOOK

| improve this answer | |

hook_preprocess_HOOK. You can add your data like $vars['my_data'] = $my_data then access it using $my_data in the tpl.

| improve this answer | |

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.