Hi folks,

I'm new to Drupal, but I've used other content managers before. Perhaps because of the way other CMS handle layout and theming, this issue I'm having in Drupal is perhaps THE most frustrating issue in Drupal for me.

Basically: how do you style a node differently depending on where you are showing it? It doesn't seem like there's an easy way to deal with it in Views, CCK or other Drupal control panels.

I see that there are recipes and tutorials around the web that demonstrate, for instance, how to make page.tpl.php aware if it's being used as the front page or not, how to add body classes in CSS based on the URL, or to style nodes differently depending on what regions they appear in. I think that these options are not quite what I want. I just want to display a group of fields differently, depending on where the node is being displayed.

Here's an example that explains why I need this:

For articles, I have a custom field type for "People" who are designated as the articles authors. The "Article Authors" field is a repeating noderelation field. (Authors, rather than being registered site members, are their own content type. We set it up this way because not all of our authors are involved in the site, but submit their stories for print first. We've also set it up this way because we want the author name in a byline to be a link to the full "detail" page of an author node that will also display all of their stories underneath.)

So I need the related "People" node to display at least three ways:

1) Title only: On an overview page of articles, I just want the author's name to display (no link) - the title of the node being pulled in as the noderelation.
2) Title + 1 custom field: On an article detail page, I want the author's name to appear in the byline (with a link to the full node), with a single custom field from the "Authors" content type beside it - their email address.
3) Full node: When the author name is clicked on, I'd like to go to the full author node, that shows not only their email address but the body field (that has a short bio) and perhaps other custom fields.

However, when I modify node-people.tpl.php, I see the changes across all three appearances.

Is there a tutorial online that shows me how to make Drupal aware of the "conditions" where the "Articles Author" noderelation field appears, and adjust the display of fields accordingly (ie. perhaps change to a different view of the node?)

I hope this wasn't too confusing. Feel free to ask questions if you need me to clarify what I've said above.

Thanks in advance to all who can offer assistance!

R o B

Comments

mndonx’s picture

Hi Rob - What you are describing sounds a lot like different variations of the same view. If you create a view, you can make several variations (block or page) of it, working off of a master view, say, "people."

In your view, you can choose to use the "node" row style (which relies on whatever you put in node-people.tpl.php). In that case you can say, <?php if ($teaser): ... ?> to see if you are on a teaser or not, but otherwise you can't customize too much from that tpl file based on what view you are using.

However, what you are describing sounds more like a "fields" view - where you specify which fields from your content type you want to expose. On your view, next to Row style, you would change it from "Node" to "Fields."

As I said above, you can have many variations upon that, and, in Views 2, you can also easily make templates (with shocking granularity). I won't try to explain it all here, but it's worth reading up on Views 2 and playing around with it to get the hang of it. It can get complicated pretty fast -- but what you are describing sounds easily doable with a few variations of the same view using "fields" instead of "node" as the row style.

Hope that helps,
Amanda