Drupal 7 - Page template suggestion based on specific alias

877 views Asked by At

I'm poor php developer and i need code for my template.php to set specific template for some pages:

Example: mypage/blog/about-me mypage/blog/about-you mypage/blog/about-us

Uses page--blog-about-first.tpl.php.

mypage/blog/about-him mypage/blog/about-her mypage/blog/about-them

Uses page--blog-about-second.tpl.php.

I can't find it anywhere so i'm asking here.

2

There are 2 answers

1
user3043693 On
  // Page template suggestions based off URL alias
  $alias=drupal_get_path_alias($_GET['q']);
  $args=explode('/', $alias);
  if ($args[0]=='blog/about-me') {
    $vars['theme_hook_suggestions'][] = 'page__simple_blog';
  }
  elseif ($args[0]=='artist') {
    $vars['theme_hook_suggestions'][] = 'page__simple_blog';
  }

This is the code. I got link /blog/about-me and link /artist. Suggestion works for artist page, but not for blog/about-me. Solution?

0
Bn Mk On

Check the naming conventions here: https://drupal.org/node/1089656

If you need to do something more complex you can use the instructions here/: https://drupal.org/node/223440#custom-suggestions