This is probably more of a PHP question than a theming one, but I hope someone can point me to the right direction.
I am trying to break down and custom develop what is in the $content variable of node.tpl.php file and having problems calling the content of an array. (I haven't worked much with PHP arrays recently, so I am too rusty there.) Here are the specifics:
- I have made a custom content type (using CCK) called "article" (that I will use storing articles.) This contains a bunch of custom fields, like authors, publication date, journal title... I confirmed that it works fine, but the default display is ugly.
- So I added a copy of the "node.tpl.php" filed named "node-article.tpl.php" file to my theme's template directory. I confirmed that it works, it is being used to display the article.
- I am trying to break down the $content variable and replace field by field with my custom displays of those fields.
- I have no problems where I have to call the content of a variable, which is a string, e.g. $title . It gets displayed exactly as I want it.
- But all of my custom fields seem to be arrays. E.g. $field_authors contains the authors of the article. I tried using
print $field_authors['value']
and
print $field_authors['0']
and
print $content->field_authors['1']
but none of these worked
What am I missing? How can I display my authors there?
Comments
You can enable/disable the
You can enable/disable the labels above CCK fields (and change a few other display settings) at
/admin/content/node-type/*CONTENT_TYPE*/display. Those changes will be reflected in a variable called$field_authors_renderedin your node template.To get at the raw values, you can use
<?php $node->field_authors[0]['value'] ?>or<?php $node->field_authors[0]['safe'] ?>for a sanitized version.If you don't already have it, the Devel module is invaluably handy. With it, you can do
<?php dpm($node); ?>or<?php dpm(get_defined_vars()); ?>in your node template and see everything available to you.Hope that helps. :)
Thank you, roper. This
Thank you, roper. This ($node->field_authors[0]['safe']) really helped and I am on my way to theming my articles.
FYI: I was aware of the CCK label settings and I have been using the Devel module and its dsm function to get my variables. I see now (here: http://drupal.org/node/174575 ) that I should use dpm.
Thanks again.