2
votes

We've created a custom module for organizing and publishing our newsletter content.

The issue I'm running into now -- and I'm new to theming and Drupal module development, so it could just be a knowledge issue as opposed to a Drupal issue -- is how to get each newsletter themed.

At this point the URL structure of our newsletter will be:

/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 one issue I'm running into is that all of the content comes through in the $content variable of the theme. I'd like to have it come through as different variables (so that I can, inside the theme, place certain content in certain areas.)

Is there a proper way for doing this?

Edit: To answer some questions: The issue is a node (there are issue, edition and newsletter nodes) and the path is being set using hook_menu with wildcards and a router.

3
are the newsletter nodes? are the url paths being generated by pathauto?Capi Etheriel

3 Answers

1
votes

The best answer I could find was to add a check inside of phptemplate_preprocess_page to send the vars back to the module and have them be updated.

Like so:

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

then in my test_module.module file 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 having to touch the theme's template.php file, but otherwise this works well.

0
votes

If there were better documentation for template preprocess functions, Drupal would be a lot more accessible - as it is, you need to piece together the information from a lot of different explanations. One place to start is here:

http://drupal.org/node/223430

but if you take the time to work through the tutorial below, you'll find you can do most things:

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

0
votes

This is an old post, and the OP's issues seems to have been solved.

However, just for others finding this through Google (or otherwise):

  1. Install the 'Devel' module: http://drupal.org/project/devel
  2. Also the 'Devel Themer' module: http://drupal.org/project/devel_themer

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

There are a bunch of Devel/Themer docs/tuts out there, but its usage is pretty straightforward. Note, though, that some stuff in there will need to be sanitized before printing in the theme.

The suggestion to show the node as a View and then modifying the view templates sounds pretty crazy, though it'll work.