I'm trying to use a page callback function to print the output into the regular $content section of my page template. For some reason, the HTML prints from my page callback function before the rest of the page.tpl.php HTML.

Here is an example of a function I'm using in my module to generate a page:

<?php
/**
* Page callback example
*/
function mymodule_page() {

	$content .= print('<p>I want this HTML to appear in the main region of my page template.</p>');
	return $content;
} ?>

Now when I load this page up I see the above HTML first, followed by the <!DOCTYPE> tag and the rest of the page.tpl.php. I tried using return drupal_render($content), and I see that there is a drupal_set_page_content coming in D7, but how is this accomplished now?

Thanks!
- Ryan

Comments

nevets’s picture

Leave out the call to print so the code would look like

    $content = '';
    $content .= '<p>I want this HTML to appear in the main region of my page template.</p>';
    return $content;

(It's good practice to initialize variables before using).