Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:39:05+00:00 2026-05-27T06:39:05+00:00

What I am trying to do is generate some raw output within a module.

  • 0

What I am trying to do is generate some raw output within a module.

I would like to pass an array of data through to a template file, and then use that data to populate the code from the template. The template is represented by a file in my theme folder.

I have a hook set up for a certain URL (/itunes):

$items['itunes'] = array(
    'page callback'     =>  'itunespromo_buildpage',
    'type'              =>  MENU_SUGGESTED_ITEM,
    'access arguments'  =>  array('access content'),
);

..inside itunespromo_buildpage…

function itunespromo_buildpage() {
    //grab some data to pass through to template file, put into $promo_data
    $details = theme('itunes_page', array(
        'promo_data'    =>   $promo_data,
    ));
    return $details;
}

Here is the hook_theme():

function itunespromo_theme() {
    return array(
        'itunes_page'   =>  array(
            'template'  =>  'itunes_page',
        ),
    );
}

Inside my theme’s template.php:

function geddystyle_itunes_page($vars) {
    return print_r($vars['promo_data'], true);
}

Right now, $promo_data is being passed through fine, and it is print_r’d on to the result page. However, I’d like to then take this $promo_data variable and use it in my itunes_page.tpl.php template file.

I’m kind of certain I’m close here. Am I supposed to call some sort of render function and pass the $promo_data variable to it from function itunespromo_theme()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:39:05+00:00Added an answer on May 27, 2026 at 6:39 am

    I believe you just need to update your hook_theme() to provide the ability to send variables to your template file.

    Something like this should do the trick:

    function itunespromo_theme($existing, $type, $theme, $path) {
     return array(
      'itunes_page'   =>  array(
        'variables' => array(
          'promo_data' => NULL,
          ),
          'template' => 'itunes_page',
        )
      );
    }
    

    Also, instead of calling the theme() function directly what you want to be doing is actually constructing a renderable array and letting Drupal call the theme() function. What you should be doing is calling drupal_render which in turn calls theme() for you. Look at this piece of advice here for a little more clarity:

    http://drupal.org/node/1351674#comment-5288046

    In your case you would change your function itunespromo_buildpage to look something like this:

    function itunespromo_buildpage() {
      //grab some data to pass through to template file, put into $promo_data
      $output = array(
      '#theme' => 'itunes_page',
      '#promo_data' => $promo_data //call $promo_data from the tpl.php page to access the variable
      );
      $details = drupal_render($output);
      return $details;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some LINQ To SQL code that would generate SQL like
I am trying to generate some custom entities and custom method to get data
I'm trying to make a website which gets some data from database and generate
I'd like to parse a SOAPUI Project file and generate some documentation from the
I am trying to generate some test data. Say I have 1000 appointments that
I am trying to generate some numbers with the rand() function like below: int
I'm trying to generate some code at runtime where I put in some boiler-plate
I am trying to generate some code at runtime using the DynamicMethod class in
I'm trying to generate some url 'slugs' for my website. It's based upon a
I am trying to generate some code using CodeDom. I wanted to know if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.