Posted by mfer on March 23, 2009 at 3:11pm
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
This is also documented in /help/content/theme-node-templates :)
That is, if you have advanced help module installed of course.
Where else?
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
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
Thanks for sharing that mfer. That is very good to know!
woohoo dancing Wow that was
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
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
I had no idea about this either. Doh! Thanks a lot
twitter: threehz
d.o: jrefano
Interesting and Funny...
_ 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:
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!
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
Skip the docs
Just do
You will see all variables.
Thanks for sharing...
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
What? for me? It's not even my birthday. Thanks
--
d.o: canarymason
twitter @canarymason
--
d.o: canarymason
twitter @canarymason
this is something
i didn't know either, thank you!
works fine in node.tpl.php but not in a module tpl.php
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