How to inject variables into page templates from a custom Drupal module?

We have created a dedicated module for organizing and publishing our newsletter.

The problem I'm currently facing is and I'm new to Drupal module development and development, so it might just be a knowledge issue, not a Drupal issue - this is how to get each topic newsletter.

At this point, the URL structure of our newsletter will look like this:

/ newsletters / {newsletter-name} / {edition-name} / {issue-date}, which means that we can create template files in our theme using filenames like page-newsletters- {newsletter-name} - {edition- name} .tpl.php which is great. The only problem I am having is that all content ends up in the $ content variable of the theme. I would like it to turn out as different variables (so that I can, inside the theme, place certain content in certain areas.)

Is there a suitable way to do this?

Edit: To answer some questions: the problem is node (there are release, release and news nodes) and the path is set using hook_menu with wildcards and a router.

+2


a source to share


3 answers


The best answer I could find is to add a check inside the phptemplate_preprocess_page to send the vars back to the module and update them.

Same:

function phptemplate_preprocess_page(&$vars) {
    if (module_exists('test_module')) {
        _test_module_injector($vars);
    }
}

      



then in my test_module.module I created this function:

function _test_module_injector(&$vars) {
    $vars[] = call_to_other_functions_to_load_vars();
}

      

It seemed to work. I wish there was a way to do this without touching the theme's template.php file, but otherwise it works well.

+1


a source


If the documentation for the template preprocess functions were improved, Drupal would be much more accessible - as you need to gather information from many different explanations. One place to start:

http://drupal.org/node/223430



but if you take the time to work with the tutorial below, you will find that you can do most of the things:

http://11heavens.com/theming-the-contact-form-in-Drupal-6

0


a source


This is an old post and the OP's problems seem to have been resolved.

However, just for others discovering this via Google (or otherwise):

Use Devel Themer to step through the $ content variable and find what you need to pull out.

There are a bunch of Devel / Themer docs / tuts out there, but using it is pretty straightforward. Note, however, that some things there must be disinfected before being printed in the subject.

Suggesting to show node as a view and then change view templates sounds pretty crazy, although it will work.

0


a source







All Articles