1

I'm trying to track down the source of some CSS issues I'm having on my site and I noticed that every page has class "page--node-" added to the <body> element. The theme hook suggestions seem to include page__node__%.

This looks weird. Is it supposed to be like this, or is there a problem in a theme hook suggestion generated somewhere? I'm using a subtheme of Zen 5.

1

Classes beginning with page generally come from drupal core in template_preprocess_html(), which calls theme_get_suggestions() to do the heavy lifting.

That function makes a bunch of suggestions for the classes or template suggestions based on the path of the current page. The % is used as a wildcard for numeric arguments (in this case the node id).

Then back in template_preprocess_html() it passes the suggestions through drupal_html_class(), which in turn runs them though drupal_clean_css_identifier(), which strips out characters not allowed in a class, including the %, so you get a class of page-node- (this seems like a bug but there is a use for it I will explain below).

This theme_get_suggestions() code is the same reason you have the template suggestion with the percent symbol.

This means you can affect all node pages by using the template name page--node--%.tpl.php.

That might not seem necessary because you also have page--node.tpl.php, however if you want a different template for the path /node than you do for individual node pages you need to use both page--node.tpl.php and page--node--%.tpl.php.

This same reason is why the unusual class is useful. If you want to style the /node page differently from individual node pages you can style page--node differently from page--node-

I agree it is a silly looking class though with pretty limited (or maybe none) documentation.

Also, something I found after writing this that is useful is How Drupal determines page theme hook suggestions based on path, from the "Drupal 7 Template (Theme Hook) Suggestions" documentation page.

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.