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 6807341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:49:14+00:00 2026-05-26T19:49:14+00:00

I need to display a page in drupal that is created by a template

  • 0

I need to display a page in drupal that is created by a template and based on a specific record from my table.

I created the module “item” (as an example).

I made the item_menu hook:

  $items['items/%item'] = array(
    'title' => 'Items',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('show_item', 1),
    'access callback' => true,
    'access arguments' => array(),
  );  

I created a load function for the item:

function item_load($itemid)
{
  $sql = 'SELECT * FROM {items} it WHERE it.id = :itemid';

  $result = db_query(
    $sql, 
    array(':itemid' => $itemid), 
    array( 'target' => 'mydatabase' ));

  $item = $result->fetchObject();
  return $item;
}

Now I want to use a template to display the specifics for the item, so I made a item module
a item.tpl.php. and a item_theme hook to register the template:

function item_theme($existing, $type, $theme, $path) 
{
  return array(
    'show_item' => array(
      'template' => 'item',
      'variables' => array(),
    ),
  );
}

The final thing I need to do is pass the item object to the item.tpl.php so I can display the item properties.

But I don’t know how to do this. How can I make the item known within the template??

I hope the question is clear enough. Thanks in advance.

[edit]

I found that arg(1) contains the value of the wildcard from the menu page arguments, should I use arg(1) to look up the item in the database?

  • 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-26T19:49:14+00:00Added an answer on May 26, 2026 at 7:49 pm

    You need to declare the names and default values for the vars you want to use in the variables part of your array in hook_theme:

    function item_theme($existing, $type, $theme, $path) {
      return array(
        'show_item' => array(
          'template' => 'item',
          'variables' => array('var1' => NULL, 'var2' => NULL, 'etc...'),
        ),
      );
    }
    

    Then call the theme function like this:

    $item_output = theme('show_item', array('var1' => $a_var, 'var2' => $another_var));
    

    ** UPDATE **

    To address the load() function being called 4 times you can use static vars to avoid the query being run every time:

    function item_load($itemid) {
      $items = &drupal_static(__FUNCTION__, array());
    
      if (!isset($items[$itemid])) {
        $sql = 'SELECT * FROM {items} it WHERE it.id = :itemid';
        $items[$itemid] = db_query(
          $sql, 
          array(':itemid' => $itemid),
          array('target' => 'mydatabase')
        )->fetchObject();
      }
    
      return $items[$itemid];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to display a Drupal view without the page template that normally
I need display data from a web page in a ListView, for example if
Hi I need to create a module in drupal to display some data, not
I have a Drupal site that needs to display a unique header image based
On a page which shows a specific object I need to display related objects
I need to display advertisement only on main page of my website (example.com). I've
i need to display the category list related to the current page (based on
I have an asp.net mvc 2 app. I need to display the same page
I have an ASP.NET web page that displays a variety of fields that need
I have a page/gsp that displays 3 different classes. This means that I need

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.