Search code examples
phpdrupal-7drupal-modulesdrupal-theming

Print a variable in theme file from drupal module


This is code of vegas.module file. it is used to load images from specific folder.

   function vegas_init() {
  // Load all the images to be added to Vegas.
  $backgrounds = array();
  $fade = variable_get('vegas_fade', 0);
  for ($i = 0; $i < 10; $i++) {
    $fid = variable_get('vegas_images_' . $i, '');
    if (!empty($fid)) {
      $image = file_load($fid);
      if ($image) {
        $background = array(
          'src' => file_create_url($image->uri),
        );
        if (!empty($fade)) {
          $background['fade'] = intval($fade);
        }
        $backgrounds[] = $background;
      }
    }
  }

I print it in .module file. It gives the expected result.

print_r($backgrounds);

If i print it in my theme's page.tpl.php it doesn't return any values. Is there any way to load module's variable


Solution

  • If you want to print this varibale in page.tpl.php - use hook_preprocess_page

    function custom_preprocess_page(&$variables), not node.