Posted By

woutr_be on 07/24/11


Tagged


Versions (?)

Drupal 7: custom template based on url alias


 / Published in: PHP
 

This will give you the ability to create custom node templates based on the URL alias of a page.

Example: if you create a page with the URL alias "aboutus", you can now use node--page-aboutus.tpl.php as your node template.

  1. function template_preprocess_node(&$variables) {
  2. if(isset($variables['node']) && $variables['type'] == "page") {
  3. $path = drupal_get_path_alias($variables['path']);
  4.  
  5. $variables['theme_hook_suggestions'][] = 'node__page_' . $path;
  6. }
  7. }

Report this snippet  

You need to login to post a comment.