Customizing the page template file

Drupal: 23m
Video Series
Information

This video walks through the process of replacing static content in the page.tpl.php file with dynamic variables. Joe talks about the html.tpl.php file as well as pointing some of the important variables that should be included within the theme.

Discussion

Comments on this video

You need to be an active subscriber to comment. or .

I pulled the main-menu print statement from Drupal's default page.tpl and pasted it into my page.tpl and the menu doesn't show up. If I create a "Nav" region and take the main-menu block into it, it'll display. But why not when hard-coded like in the tutorial?

Unfortunatly this is going to be a hard one to debug without being able to have access to your particular setup. However, here's some thoughts.

I assume that you're referring to this line of code.

<?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' ...

I would verify that $main_menu has something in it. <?php var_dump($main_menu); ?>

Verify your menu settings and make sure that the "Source for main menu links" is set at admin/structure/menu/settings.

I would also try turning off any modules that might be trying to do things with the menu system just to confirm that it isn't some kind of conflict.

Those are the things I can think of off the top of my head. I'll follow up if I come up with any others.

Hey Joe,
Thanks for the reply. I have no idea why the menu wouldn't display, there is certainly content in it. I was able to get the menu and it's children to display by adding a couple lines to template.php and adding this to my page.tpl:

<?php $menu = menu_tree('main-menu'); print render( $menu ); ?>

template.php:

function mytheme_preprocess_page($variables) {
// Get the entire main menu tree
$main_menu_tree = menu_tree_all_data('main-menu');
// Add the rendered output to the $main_menu_expanded variable
$variables['main_menu_expanded'] = menu_tree_output($main_menu_tree);

The menu still doesn't work correctly though. It looks like the parent UL is expanding to accomodate the the children UL's. What's odd is that it follows the same html structure & css from my static comp and still doesn't look right. (I've denied it system.menus.css)

Why are you not discussing the significance of render($page)

@marlenayers, significance as in why Drupal 7 switched to using the render($page) method? If that's what you're wondering about we do talk about it a bit more in the next couple of chapters, especially the one about modifying node template files. And then we get in to the whole Render API in more depth in the advanced theming series. We wanted to try and take the approach of gently introducing renderable arrays since they can be a bit complex and settled on the "show/explain what you need to know when you need to know it" method vs. trying to just explain it all in one sitting. So in this chapter, yeah it's a little light, but we cover show()/hide(), hook_page_alter(), creating your own renderable structures, and even talk a bit about why Drupal choose this pattern in more of the videos in this series and the advanced one.

There is also this page in the drupal.org handbook which has some good information. http://drupal.org/node/930760

If you have specific questions though feel free to ask and we can help answer them and/or point you to additional resources.

I have a basic question about the main menu. What css technique are you using to display the background color for the current page link?

Lullabot logo

Lullabot has trained thousands of Drupal developers & guided the development of some of the largest Drupal websites.