Drupal Page template file based on url


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //Drupal 5
  2. <?php
  3. function _phptemplate_variables($hook, $vars = array()) {
  4. switch ($hook) {
  5. case 'page':
  6.  
  7. // Add page template suggestions based on the aliased path.
  8. // For instance, if the current page has an alias of about/history/early,
  9. // we'll have templates of:
  10. // page-about-history-early.tpl.php
  11. // page-about-history.tpl.php
  12. // page-about.tpl.php
  13. // Whichever is found first is the one that will be used.
  14. if (module_exists('path')) {
  15. $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
  16. if ( $alias != $_GET['q'] && $alias == $_REQUEST['q'] ) {
  17. $suggestions = array();
  18. $template_filename = 'page';
  19. foreach (explode('/', $alias) as $path_part) {
  20. $template_filename = $template_filename . '-' . $path_part;
  21. $suggestions[] = $template_filename;
  22. }
  23. }
  24. $vars['template_files'] = $suggestions;
  25. }
  26. break;
  27. }
  28.  
  29. return $vars;
  30. }
  31. ?>
  32.  
  33. //Drupal 6
  34. <?php
  35. function phptemplate_preprocess_page(&$vars) {
  36. if (module_exists('path')) {
  37. $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
  38. if ($alias != $_GET['q']) {
  39. $template_filename = 'page';
  40. foreach (explode('/', $alias) as $path_part) {
  41. $template_filename = $template_filename . '-' . $path_part;
  42. $vars['template_files'][] = $template_filename;
  43. }
  44. }
  45. }
  46. }
  47. ?>

URL: http://drupal.org/node/139766

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.