2

I've got an issue which I'm not sure how to address. I've got a specific page that I've set as front page. I've created a custom template for it and named it page--front.tpl.php and it was as expected until I've added page--node--page.tpl.php which seems to be overriding page--front.tpl.php.

Is this the correct and expected behaviour? How can I force it the page--front.tpl.php to be used?

I'm using Drupal 7 with and a child of the Bootstrap's theme.

1
  • Don't have time to test for sure, but try implementing hook_preprocess_page() and re-ordering the $vars['theme_hook_suggestions'] array into something that suits you better – Clive Jul 23 '15 at 9:14
1

If you need to have a custom theme for nodes, try to do this using THEME_preprocess_node as follow

function THEME_preprocess_node(&$variables){
     $node = $variables['node'];
     if($node->type == "SOME_CONTENT_TYPE")
          $variables['theme_hook_suggestions'][]='page__node__SOMETHING';
}

Then create page--node--SOMETHING.tpl.php in your theme folder. To get the values of the fields you can use the entity module and do something like the following code (I supposed field_something is machine name of one of your fields):

function THEME_preprocess_node(&$variables){
     $node = $variables['node'];
     if($node->type == "ANY_CONTENT_TYPE"){
        $variables['theme_hook_suggestions'][]='page__node__SOMETHING';
        $wrapper = entity_metadata_wrapper('node',$variables['node']);
        $variables['title'] = $wrapper->title->value();
        $variables['something'] = $wrapper->field_something->value();
     } 
}

By this code $title and $something variables are available in page--node--SOMETHING.tpl.php file.

4
  • That didn't quite work. It put page--front.tpl.php inside my page--node--page.tpl.php – WagnerMatosUK Jul 23 '15 at 11:14
  • Did you clear the cache? Did you remove page--node--page.tpl.php? Put the code of front page in the question – M a m a D Jul 23 '15 at 11:26
  • Yep, I did, using it drush – WagnerMatosUK Jul 23 '15 at 13:22
  • Like I said put your page--front.tpl.php and template.php code in here – M a m a D Jul 23 '15 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.