Search code examples
drupaldrupal-templates

Different templates for a content type inside and outside a view


I have prepared two different templates for Article content type nodes. I would like to use one of the templates in the front page (and show them inside a View, as an unformatted list), and the other template in the rest of the site (outside a View).

I can just define node--article.tpl.php for all the articles, but I have no idea to define another one for the some nodes when they are part of a view (or inside the front page, I don't matter what to use to differentiate both).


Solution

  • I finally learnt a lot more about Drupal 7 and the proper way to do it is (without any code, just using proper names for template files):

    • Using node--article.tpl.php as the template name for the detailed view of the article.
    • Using node--view--[name-of-the-view].tpl.php as the template name for the alternative view for the same articles when they are inside a name-of-the-view view. No matters what kind of nodes are inflated inside the view, this template is taken before the general one.