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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:00:28+00:00 2026-06-01T04:00:28+00:00

In a module I am developing, I am using the following code. function mymodule_page_alter(&$page)

  • 0

In a module I am developing, I am using the following code.

function mymodule_page_alter(&$page) {
  global $user;

  $page['sidebar_first'] = array(
    '#markup' => 'text for first sidebar'
  );
}

How can I load the HTML template file to the first side bar, and pass few variables to this?
Maybe this will be something like the following code.

$page['sidebar_first'] = array(
  '#template' => path,
  '#variables' => array(),
);
  • 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-06-01T04:00:30+00:00Added an answer on June 1, 2026 at 4:00 am

    You need to use the “#theme” attribute, such as in the following code.

      $build['dblog_table'] = array(
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => $rows,
        '#attributes' => array('id' => 'admin-dblog'),
        '#empty' => t('No log messages available.'),
      );
    

    #theme tells to Drupal which theme function needs to be called; the other properties, if they are already used for a different purpose, are used as variable names to pass to the theme function, or the template file, if one is used.

    In the example, theme_table() will receive the following array.

    array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array('id' => 'admin-dblog'),
      'empty' => t('No log messages available.'),
    );
    

    This can be done even with those theme functions that really use a template file.

    You define a theme function in your hook_theme(), using the necessary keys used for a theme function that uses a template file, such as in the following code.

    function mymodule_theme($existing, $type, $theme, $path) {
      return array(
        'mymodule_sidebar' => array(
          'variables' => array('topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL),
          'template' => 'mymodule-display',
        ),
      );
    }
    

    The theme function would be then used with something similar to the following code.

    $page['sidebar_first'] = array(
      '#theme' => 'mymodule_sidebar',
      '#topics' => array('first topic', 'second topic', 'third topic'),
      '#parents' => array('my topics', 'my friend's topics'),
    );
    

    The variables that don’t get an explicit value will get the default one reported in hook_theme(); in this case, the default value for the used variables is NULL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using the following method in a new application i'm developing. there is
I am developing a module for Python using a C API. How can I
I am developing a payment Module for Magento. I did this using this tutorial
I am developing an archive module for an application using Dotnet and SQL Server
I am developing an application in Flex using the cairngorm module library and Parsley.
I'm developing an ASP.NET authorization module, and so far it works beautifully when using
While developing desktop applications using Perl Win32::GUI module in windows OS, a camel image
I've got a helper script for a Joomla 1.0 module I'm developing. I'm using
I'm developing a drupal module. I'm using only 2 hooks (hook_menu, hook_cron) In hook_menu,
I am developing a web app using Kohana 3.2 with the following modules loaded:

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.