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 ?

1 Answer 1

-2

How about:

...
$rdr = array(
  '#theme' => 'opendtp_slide',
  '#module_path' => drupal_get_path('module', 'mymodule')
);
...
2
  • The OP is asking the reason why the error appears.
    – apaderno
    Jan 20, 2014 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, 2014 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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