Quantcast
Channel: Recent posts across whole site
Viewing all articles
Browse latest Browse all 49197

so close, but so far, with hook_preprocess_node()

$
0
0

Thanks everyone for your thoughts and suggestions at last night's meetup. I'm very close to a solving the problem I showed you. But I'm still missing a step (a function I think). Any help would be greatly appreciated.

Recap of problem:

I'm calling hook_nodeapi() to re-arrange weights of things like this...

$node->content['video']['#weight'] = 0;
$node->content['map']['#weight'] = 1;
$node->content['pic']['#weight'] = 2;
$node->content['body']['#weight'] = 3;

Then, something comes along and resets the weight of my body to 0, which is messing up the order of things on my node pages.

Solution: hook_preprocess_node()

The solution suggested last night was to use hook_preprocess_node(). Please see my notes in the code below to see where I'm hung up inside this new, exciting hook....


mymodule_preprocess_node(&$vars) {

   // This gets me back to $node->content with all the weights as I want them.
  $vars['node']->content['body']['#weight'] = 3;  
 
  // My problem is that Drupal seems to be done with $vars['node']->content.
  // $vars['content'] is what is getting printed. So I think I need to do something like this...
  $node = $vars['node'];
  $new_content = some_function($node->content); // re-generate the HTML from $node->content
  $vars['content'] = $new_content;

}

I feel certain that "some_function()" exists. Does anyone know it's name? Or am I barking up the wrong tree here?

Bryan

(A side note: hook_preprocess_node(), seems really powerful. But I don't see documentation about it at api.drupal.org. Strange. Am I missing something?)


Viewing all articles
Browse latest Browse all 49197

Trending Articles