Drupal - Change templates based on path alias
You can add some logic in a hook_preprocess_page()
implementation that checks the alias, and adds theme hook suggestions if the path matches, e.g.
function MYTHEME_preprocess_page(&$vars) {
$alias_parts = explode('/', drupal_get_path_alias());
if (count($alias_parts) && $alias_parts[0] == 'mydirectory') {
$vars['theme_hook_suggestions'][] = 'page__mycustomtemplate';
}
}
Then if you create a page--mycustomtemplate.tpl.php
file in your theme, and clear the cache, any pages with an alias beginning mydirectory/
will use that new file instead of the standard page.tpl.php
.
It's actually easier than that using drupal_match_path() which is how the blocks module works out whether a block should be displayed on a page or not:
function MYTHEME_preprocess_page(&$vars) {
if (drupal_match_path(drupal_get_path_alias(), 'mydirectory/*')) {
$vars['theme_hook_suggestions'][] = 'page__mycustomtemplate';
}
}