3

I'm new at Drupal, coming from the PHP framework world, and I'm having some problems understanding the the template hierarchy in Drupal 7.

I've created a template called 'node--article.tpl.php' and can style my single article nodes. The problem is that this affects the front page as well. I want to style the node list different then when displaying single nodes. How can I do this?

4

Berdir's suggestion (coolest imho):

you can even provide custom template suggestions based on the view mode. See for example drupal.org/node/223440 and bri-space.com/content/creating-drupal-template-suggestions

Also within node-article.tpl.php you can inspect $view_mode and decide what to do. You could either include the logic of both templates in the one file, or create different templates and include the appropriate one based on the value of $view_mode

You might also find Display suite interesting.

|improve this answer|||||
  • I want to render different templates when listing nodes on the front page and when displaying a single node – sandelius Mar 26 '11 at 10:58
  • Within node-article.tpl.php you can inspect $view_mode and decide what to do. You could either include the logic of both templates in the one file, or create different templates and include the appropriate one based on the value of $view_mode. – Andy Mar 26 '11 at 13:10
  • 1
    Or you can even provide custom template suggestions based on the view mode. See for example drupal.org/node/223440 and bri-space.com/content/creating-drupal-template-suggestions – Berdir Mar 26 '11 at 13:42
  • is there a function to render a file from the current theme? – sandelius Mar 26 '11 at 13:55
  • @Berdir +1 that's nicer! @sandelius don't really understand? – Andy Mar 26 '11 at 14:18
2

By using Views module, you can create custom displays of node lists (and many other things). This is your master page builder tool for Drupal. http://drupal.org/project/views

With views, you can define the type of view (normal node teaser view, list using select fields, etc.), filters (e.g., show only article nodes, not other node types), sorting order, and so on. Views also has this power for listing users, comments, taxonomy… And you can define these views for pages (where the view you define is the content in the main content area), blocks that appear on any page, and even RSS feeds.

|improve this answer|||||

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.