i can never remember the complete structure of the field array, the best way to see what's available is to do:
<?php
print_r ($node->field_fieldname);
?>
=== "Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu "God helps those who help themselves." -- Benjamin Franklin "Search is your best friend." -- Worldfallz
You can also install devel module. It gives you all the node values you need.
And by the way: If I'm not mistaken page.tpl.php only carries $node-data when it's a single node page.
Otherwise you will have put your code in node.tpl.php or node-MyContentType.tpl.php
The advice given in the previous posts is right on. I'm looking from a different point of view though. What about if the page is a view or an admin page? I think you want to be putting your code in node.tpl.php unless you are already putting proper guards around this code.
I don't get any output when trying: print_r ($node->field_filvedlegg['value']). (print_r ($node->field_fieldname) worked just fine)
The reason I don't wont to put this in node-MyContentType.tpl.php is that I want to posision my field at the top of the page, away from the rest of the node.
Btw, I'm all new to Drupal, so maybe there is another easier way.
Well, when things get desperate, you can always do print_r($node) and see the whole thing. var_dump($node) makes it look a little nicer, but won't show you the entire structure. It may take a little while to sort it all out, but it can be informative. Usually CCK fields will have ['value'] and ['view']. The value is the raw data and the view is usually formatted for display. You'll probably want to be using the view portion.
If this field really makes sense somewhere outside the main content area, it may make sense to make a custom block and place it in a bock region. But that's only going to be possible after your grasp these concepts anyhow. Perhaps if you gave us more information about your content type and desired page layout, we could offer some advice.
=== "Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu "God helps those who help themselves." -- Benjamin Franklin "Search is your best friend." -- Worldfallz
Comments
Try <pre><?phpprint
Try
to see the elements of field_myfield. I believe you want $node->field_myfield['value'].
i can never remember the
i can never remember the complete structure of the field array, the best way to see what's available is to do:
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
devel module
You can also install devel module. It gives you all the node values you need.
And by the way: If I'm not mistaken page.tpl.php only carries $node-data when it's a single node page.
Otherwise you will have put your code in node.tpl.php or node-MyContentType.tpl.php
The advice given in the
The advice given in the previous posts is right on. I'm looking from a different point of view though. What about if the page is a view or an admin page? I think you want to be putting your code in node.tpl.php unless you are already putting proper guards around this code.
Thanks for all the replies.
I don't get any output when trying: print_r ($node->field_filvedlegg['value']). (print_r ($node->field_fieldname) worked just fine)
The reason I don't wont to put this in node-MyContentType.tpl.php is that I want to posision my field at the top of the page, away from the rest of the node.
Btw, I'm all new to Drupal, so maybe there is another easier way.
Well, when things get
Well, when things get desperate, you can always do print_r($node) and see the whole thing. var_dump($node) makes it look a little nicer, but won't show you the entire structure. It may take a little while to sort it all out, but it can be informative. Usually CCK fields will have ['value'] and ['view']. The value is the raw data and the view is usually formatted for display. You'll probably want to be using the view portion.
If this field really makes sense somewhere outside the main content area, it may make sense to make a custom block and place it in a bock region. But that's only going to be possible after your grasp these concepts anyhow. Perhaps if you gave us more information about your content type and desired page layout, we could offer some advice.
print_r ($node->field_myfield['value']) don't work?
Am I using the correct syntax?
print_r ($node->field_myfield) works fine.
IIRC, i think
IIRC, i think it's:
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Thanks
Thanks
This seemed to work for me
This seemed to work for me
<?php print t($node->field_my_field[0]['view']); ?>Thx for ur reply
Thx for ur reply Kathy303Beck,
Its working in page.tpl.php when we are login else it doesn't work.
@aakanksha - If you are
@aakanksha - If you are seeing it when you are logged in, you might need to change some of the anonymous user permissions.
It's working, but when
It's working, but when displaying a node of another node type which doesn't have that field, it just says "Array". Is there a way to remove that?
You could try <?phpif (
You could try
Works perfectly, thanks a
Works perfectly, thanks a lot!
You don't need to place that
You don't need to place that in a
t()string. t() makes words inside the brackets translatable strings.print fields in page.tpl.php in Drupal 7
this works for me.
Undefined index error
The above worked for me except I was getting an error;
Notice: Undefined index: und in include() (line 47 of /home/... .../page.tpl.php).
To fix the problem I simply changed the code to;
This was suggested further above, hope this helps if anyone else gets this error.