1

I'm using hook_menu to build a series (100+) of pages where the code uses a basic page "master template" and replaces strings in the "master template" node with elements of the URL that reaches the Drupal menu page callback routine.

Once the appropriate strings are replaced, the page callback routine uses node_view() to create the render array, and returns it for further processing and transmission to the client.

The "master template" page is at URL mysite/whatever-string. The problem is that Drupal sticks whatever-string into the page the client receives, and it looks like this:

<div class="content">
    <div id="node-1196" class="node node-page contextual-links-region clearfix"
         about="/whatever-string" typeof="foaf:Document">

        <h2 class="title"> <a href="/whatever-string"></a>
        </h2>
        ....

I'm using dd($var, 'description') to look at data structures and elements as a debugging tool. From the callback routine, dumping the unprocessed and processed "master template" node and the render array returned by node_view() and searching for whatever-string returns no results. The string isn't there. Thinking that perhaps the render array produced by node_view() didn't have all of the elements that the page contained, I implemented hook_page_alter($page) to see if the render array that it gets as a parameter might contain the string. It doesn't. Is there some other hook that's available to a module which will have everything that goes into rendering the page ?

As a last resort, I'm sure I can work around this by writing theme/template code to wander through the html (or DOM) and make the changes needed. I've done this a lot before, but I think it's cleaner (and marginally more efficient) to do it all when the page is generated, rather than looking at all the nodes that get rendered to see if it's a generated one, and make the changes to the HTML directly.

0

I would suggest using hook_preprocess_HOOK. In this instance I think hook_preprocess_node is what you want but _page may work as well.

0

Unfortunately when we try to subvert the Drupal workflow in favor of 'marginally more efficient' cpu/resource utilization, we will constantly run into this kind of problem. ;)

Drupal wants you to override the 'node' template in this case. It sounds like you may already be aware of this.

You may be able to limit the effect of this template override if all your 'interesting' nodes share a content type/s. In which case, you may add a template suggestion to your theme's 'template.php';

function THEME_preprocess_page(&$vars, $hook) {
  if (isset($vars['node']->type) && $vars['node']->type === 'my_interesting_type') {
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
}

More info on this template suggestion workflow; https://www.drupal.org/node/1089656

  • In this case, I couldn't split the content out to a different site (modifying existing, not implementing for the first time). – oldcoder Apr 1 '15 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.