2

I'm trying to replace the theme() with render() as recommended:

https://api.drupal.org/api/drupal/includes!theme.inc/function/theme/7
So I started with:

 function mymodule_block_view()
 {      
  $variables['module_path'] = drupal_get_path('module', 'mymodule');
  $block['subject'] = t('mymodule Slide');
  $block['content'] = theme('mymodule', $variables);
    return $block;
  }

And I tried

 function mymodule_block_view()
 {   
    $variables['module_path'] = drupal_get_path('module', 'mymodule');
    $block['subject'] = t('OpenDTP Slide');
    $rdr = array(
      '#theme' => 'opendtp_slide',
        '#module_path' => $variables['module_path'],
     );
    $block['content'] = render($rdr);
    return $block;
}

But it says Undefined variable for module_path that I used in the tpl.php file. How I'm a supposed to use variables in the template then ? What is the correct way of doing it ?

-2

How about:

...
$rdr = array(
  '#theme' => 'opendtp_slide',
  '#module_path' => drupal_get_path('module', 'mymodule')
);
...
| improve this answer | |
  • The OP is asking the reason why the error appears. – kiamlaluno Jan 20 '14 at 23:46
  • Your suggestion is cleaner than what I had but this is not the issue origin because I declare it before in the $variables array. – eXa Jan 22 '14 at 15:08

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.