technonaturalist

image link to hive image link to ko-fi

Drupal 7 notes: node or page template by path

posted on: Tuesday, 5 February 2013 @ 6:55pm in
tagged

Because I always seem to manage to completely forget how to do something this basic.

template.php in theme_preprocess_page(&$variables) or theme_preprocess_node(&$variables)

<?php
  $path = drupal_get_path_alias();

  if (strpos($path, 'part_of_url') !== false) {
    $variables['theme_hook_suggestion'] = 'page__whatever'; // or node__whatever if using in a node preprocess
  }
?>