0

I have a node--mynodetype.tpl.php, the problem that I have is that I have a module to show public contents.

In this module I need to render something completely different to what is in node--mynodetype.tpl.php.

So I was thinking to create a file named, for example, node--mynodetype-public.tpl.php but I was googling and I can't find a function to select one node template or other node tpl.

Is this any function to select wich node template to render?

Thanks in advance.

1

1 Answer 1

2

Unless I am missing something here, this is a classic job for hook_preprocess_node(), eg...

function YOURMODULEORTHEME_preprocess_node(&variables) {

  if ( /* whatever logic */ ) {
    $variables['theme_hook_suggestions'][] = 'node__YOURNODETYPE_public';
  }

  // other preprocessing here

}

...which would cause Drupal to look for a node--YOURNODETYPE-public.tpl.php template when whatever logic was true.

Read Working with Template Suggestions and Theme Suggestions for a lot more info on all of this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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