0

I need to alter the body html for a specific content type which will be processed by the Pagination module. I think preprocess_node will work, but I'm having trouble figuring out how to change the body content.

function mytheme_preprocess_node(&$vars) { 

  // Collect / create / adjust new body content
  $new_body = $vars[??];
  $new_body = _mytheme_do_stuff();

  // Assign to output
  $vars[??] = $new_body;
}

When I look into $vars I see many options ($vars['body'], $vars['content'], $vars['node'], etc). I'm probably close, but I haven't been able to affect the output yet. Anyone know what I should be targeting?

If there's a better approach, I'd love to hear that too.

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

An alternative way is to create a new variable and assign your function output to it like below

$new_body = _mytheme_do_stuff();

// Assign to output
$vars['new_body'] = $new_body;

new_body variable will now be available in your template file. So instead of printing body print $new_body in your template (tpl.php)

  • I need the Pagination module to process my altered body markup, so this probably wouldn't work, right? I'm trying to figure out how to modify the body before Pagination begins working on it. – doub1ejack Nov 5 '14 at 17:36
  • What basically you want to do with body?- I am kinda confused with the question – Shabir A. Nov 5 '14 at 17:59
  • After thinking about it, it doens't matter if I catch the body before or after Pagination alter's it. The only important thing is that the body is altered by both my code and Pagination. – doub1ejack Nov 5 '14 at 18:00
  • I'm going to inject some markup around specific image tags. – doub1ejack Nov 5 '14 at 18:01
  • then I would suggest to add new variable change your body in preprocess and pass it to pagination and process it there – Shabir A. Nov 5 '14 at 18:13
0

It is as simple as altering $vars['content']:

function mytheme_preprocess_node(&$vars) { 

  // Collect / create / adjust new body content
  $new_body = $vars['content'];
  $new_body = _mytheme_do_stuff();

  // Assign to output
  $vars['content'] = $new_body;
}

The content does appear to have already been altered by the Pagination module at this point. For my case, though, that's ok.

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.