Add Drupal page template suggestions based on path alias.


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



Copy this code and paste it in your HTML
  1. /**
  2.  * Override or insert variables into the page templates.
  3.  *
  4.  * @param $vars
  5.  * An array of variables to pass to the theme template.
  6.  * @param $hook
  7.  * The name of the template being rendered.
  8.  */
  9. function genesis_custom_preprocess_page(&$vars, $hook) {
  10. // Add page template suggestions based on path alias.
  11. $alias = drupal_get_path_alias($_GET['q']);
  12. if ($alias != $_GET['q']) {
  13. $template_filename = 'page';
  14. foreach (explode('/', $alias) as $path_part) {
  15. $template_filename = $template_filename . '-' . $path_part;
  16. $vars['template_files'][] = $template_filename;
  17. }
  18. }
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.