Drupal 7 override page.tpl.php for specific content type

| Drupal Development | 12 seen

<p>Working on project I needed a function to override default page.tpl.php for specific content type. I did use theme_hook function some 2 years ago, and I knew it's achievable in Drupal.</p><p>Doing quick Google search found a Drupal tutorial <a href="https://drupal.org/node/249726">https://drupal.org/node/249726</a>&nbsp;- &nbsp;don't know is it problem with my project, but that didn't work as expected, and after brief investigation I found a solution:&nbsp;<a href="https://drupal.org/node/1089656#comment-4662688">https://drupal.org/nod… a new page.tpl.php for your specific content - for example page--acommodations.tpl.php</p><p>In your template.php file add:</p><blockquote><pre>function YOURTHEME_preprocess_page(&amp;$vars, $hook) {<br> if (isset($vars['node'])) {<br> // If the node type is "accommodation" the template suggestion will be "page--accommodation.tpl.php".<br> $vars['theme_hook_suggestions'][] = 'page__'. $vars['node']-&gt;type;<br> }<br>}</pre><pre>&nbsp;</pre></blockquote><pre>Remember to change YOURTHEME to name of your theme. Clear all caches, and now you can start theming page for specific content type.</pre><p>&nbsp;</p><p>&nbsp;</p>

Add new comment