tags:

views:

177

answers:

3

Hi all,

I've created a new content type called Homepage, which has a number of fields. The fields are node references to the Single Image Promo content type. Single Promo Box has fields for title, text and image. The idea is that I can create multiple copies of a Single Promo Box, each with different field values. I then want to place a few of them on the homepage.

So I can place a specific Single Image Promo on the homepage fine now. But what template file do I need to create to style the way Single Image Promo is shown when it's a node reference on the homepage?

Thanks, Maria

A: 

It sounds like you are over complicating things.

If you want to create some different boxes on your homepage, using node reference is not the right way to go about this. There are some few different ways to do what you want, the easiest i probably to create a block view of the node you want to display. When you turn a node into a block, you get the ability to place it in any of your theme's defined regions.

You could also just create a view and from there get the different Single Image Promo you want without using node reference at all. Views has a lot of different filters, which will enable to you create a view that always displays the right nodes. This solution wont work well, if you want to place the nodes in different regions though.

To answer your question, when nodes are being displayed, they will by default be rendered with the node.tpl.php template file. To make specific templates for each of your node types, you can create a new template named node-nodetype.tpl.php, where nodetype is what you called the node type when you created it.

googletorp
Thanks googletorp, That's what I did in the end, created a view for it and setup a block display. I had tried this in the past, but where I fell down was specifying which specific node the view should be for. I then discovered the view filters, which I am now using. Seems a little heavy that I must create a view for every node though.
Maria
A: 

node-nodetype.tpl.php can work to a certain degree, but in that file you are styling the entire page, with the content type's fields delivered wholesale to the tpl via a single $content variable. Maybe it is enough for you, but if you need finer grained control:

You can edit and style the individual content type's fields with the Content Template (contemplate) module. It provides access to all of a content type's fields within the $content variable (which is delivered wholesale to the node-nodetype.tpl.php. The contemplate is php, so you can add logic and conditional formatting for the node-reference fields (usually clearly labeled in the contemplate).

And don't overlook the simple solution of the content type's 'display fields' tab (next to manage fields tab), where you can control some field outputs right out of the gate.

Kirk Hings
A: 

If I got you right, what you want to do is having a template that will format the nodes you inserted by nodereference in a different way from the way you see them when displaying the same nodes as individual pages.

If I got you right I think this screencast (about 16 minutes) explains exactly what you want to achieve.

I do not know if you are over-complicating things or if you simply must use this approach for some reason you did not disclose, but given that I understand you are displaying only nodes of a given type in the "mother page", I would certainly suggest to evaluate weather the views module might be a better solution for you or not. As already pointed out by googletorp, views offer a lot of flexibility in terms of data filtering, sorting and theming.

HTH!

mac