I have a requirement to apply template to a specific page and not to the pages following the same url pattern. For example I have a page with the path /asia. I also have pages with the paths /asia/india, /asia/china etc. I would like to create a template which applies only for /asia and not for other paths. I created the template file page--asia.tpl.php but it is getting applied for /asia/india and /asia/china as well. Is there a way to specifically map the template to this specific path?
2 Answers
To overwrite Drupal defalut suggestion, You can make your own suggestion for template.
In your case you have defined a menu called asia for that specific template is required, to implement this use this code
**
* Implementation of hook_preprocess_HOOK().
*/
function mymodule_preprocess_page(&$variables){
if(isset($variables['asia']) && arg(1) == '')
$variables['theme_hook_suggestions'][] = 'page__asiapage';
}
create a tpl file in theme called page--asiapage.tpl.php, it will work.
-
1Thanks Ramesh! This worked.I used the condition
if(arg(0)=='asia' && arg(1)=='')
instead of the one specified above.– BhuvanaCommented Feb 4, 2014 at 10:23
Follow the below points:
- Create a file with the name "page--node--nodeid.tpl.php" template.
- Replace nodeid with the node you want to theme.
- Clear the performance.
-
Thanks for the reply Astha! This solution doesn't work in my case since the page is an empty pagecallback and not a node.– BhuvanaCommented Feb 4, 2014 at 10:36