Displaying fields in tpl files

Events happening in the community are now at Drupal community events on www.drupal.org.
mfer's picture

Displaying fields in tpl files, like the node.tpl.php files, is a common desire to designers/themers. After conversations in IRC, at drupalcon, and in the parking lots of the Internet the common thought is that you need to make calls to something like $node->content['field_FOO']['#XXX']; to get to the information.

I've recently learned that there is an easier way to get to it. According to yched, on of the gurus of CCK and fields, you can use $FIELD_NAME_rendered in your .tpl files where fields are attached. This is true in Drupal 6 CCK and Drupal 7 fields.

Just wanted to pass this on to those that can find it useful...

Comments

In advanced help pages

manuel garcia's picture

This is also documented in /help/content/theme-node-templates :)

That is, if you have advanced help module installed of course.

Where else?

mfer's picture

This should be documented elsewhere as well. A lot of designers/themers don't know about this. Where else can we share this?

Matt Farina
www.innovatingtomorrow.net
www.geeksandgod.com
www.superaveragepodcast.com
www.mattfarina.com

That's the only place I found it

manuel garcia's picture

Perhaps we should create the same pages on the documentation section for CCK?
That's the most logical place to be I guess, but really advanced help module has great info, and everyone should read up on that.

Thanks for sharing that

flickerfly's picture

Thanks for sharing that mfer. That is very good to know!

woohoo dancing Wow that was

mortendk's picture

woohoo dancing
Wow that was some good stuff to know.
and yup placing that kind of information should not be in the advanced help but hmm let me see ... ooh yeah in the theming handbook ;)

/morten.dk king of rock
morten.dk | geek Royale

/morten.dk king of rock
morten.dk | geek Royale

Whoa

ghankstef@drupal.org's picture

had no idea. So much easier. I wonder if it works on date fields to spare me from having to use format_date. Hmmm

uhhh

jrefano's picture

I had no idea about this either. Doh! Thanks a lot

twitter: threehz
d.o: jrefano

Interesting and Funny...

design_dog's picture

_ Oddly enough - I just took an Advanced Views2 Class with Victor Kane!
Which was great. (I'm not affiliated with it.) http://groups.drupal.org/node/19335

____ And (being somewhat a Designer cough) Guess what the first question was towards the end of the class??
/// Pretty much this same topic/ only with Views! How to pull Views into parts or isolated parts of a .tpl file or your template or a specific page. (a few developer type peoples where scratching their head a little trying to understand why this is so important.)

This is a huge piece of information for a Designer. Especially if they understand the concept.
Most people know - They just ask a very common different question, which is - how do I layout or place chunks of my content on the homepage?

Sorry! // Back to the topic// I had no idea that you could do this with just straight fields!
Especially since:

more and more people are getting into Grid Systems // This sort of information is hugely valuable // because the combination of the two kick butt.
this stuff is going to work out the box in 7.

I'm sure knowing Drupal there may be more than one way to do it. :-) heh. but / I'd love to see some demo or a snippet of code somewhere.

Awesome! - Por Favor / Handbook Handbook!

Thanks for Pointing This Out!

attheshow's picture

I think I had heard this, but it didn't really stick with me last time. Thanks for pointing it out again. I just added a snippet/clip for myself in Coda so I'll find it the next time I need it!

Mark W. Jarrell
Manager of Web Services
Jones Knowledge Integration Group, Inc.
http://jones.com
http://jonesdifference.com
http://jiu.edu
http://jonesknowledge.com
Twitter: attheshow

Mark W. Jarrell
Online Applications Developer
Richland Library
http://www.richlandlibrary.com
http://fleetthought.com
Twitter: attheshow

Skip the docs Just

moshe weitzman's picture

Skip the docs

Just do

print_r(get_defined_vars());

You will see all variables.

Thanks for sharing...

noussh's picture

Thanks for sharing..

There is a great video at http://www.group42.ca/taking_logic_out_of_your_template_files_from_drupa... on removing logic from .tpl files..

check out..

www.noussh.com
'be the change you wish to see in the world' - gandhi

A gift

mason@thecodingdesigner.com's picture

What? for me? It's not even my birthday. Thanks

--
d.o: canarymason
twitter @canarymason

--
d.o: canarymason
twitter @canarymason

this is something

aliciatheduff's picture

i didn't know either, thank you!

tsvenson's picture

Thanks for sharing, great knowledge.

Unfortunately this only seems to work in node.tpl.php. In any themed module tpl.php it doesn't work.

On the other hand, custom preprocess variables has the same problem.

Been banging my head about how to get excluded fields accessible from a modules tpl.php for the same nodes...

--
/thomas

--
/thomas
T: @tsvenson | S: tsvenson.com

Theme development

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week