Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By encho on
Anyone knows how to put cck field(s) into Page.tpl.php? For node template it is easy - just call <?php print $node->field_mycckfield[0]['view'] ?>
But how to do it in page's template? I guess it should somehow refer to a node then pull the cck info from it.
Comments
(no title)
According to http://drupal.org/node/11812 the $node variable is available in page.tpl.php in Drupal 5 if you are in a full node page.
Otherwise you could probably load a specific node object using its 'nid' into a variable of yours, using http://api.drupal.org/api/function/node_load/5
Sometimes a node, sometime not
page.tpl.php has $node as a variable which is set when viewing a single node. So one could check to see if $node is set, probably want to check that it is the correct type and then print the field if set. I do wonder though why you would want to print cck fields directly in page.tpl.php.
...
Well, I would like to display cck related to a node, but not as a part of a node, but in a separate area. I have tried using a block, but it did not work for me. So anyone having an idea how to call cck field outside node, please help.
You can place in a block, just takes extra work
You can access the information inside page.tpl.php, the code just need to check that $node->type is of the type you want, then any fields should be available as they normally would. You can do the same thing in a block, you just need to get $node. So you would have code something like
cool
Thanks very much for your effort. Will try it asap.
...
It does not seem to work, output looks empty :-(
Any ideas?
What does your code look like
It would help if you posted the code you have so far.
here it is
Just calling cck field like I would in node template. I am beginner in this, so might need something else:
Need to change 'your_type'
Need to change 'your_type' to the actual type that you are interested in. For example if you had called your type 'cars', you would replace 'your_type' with 'cars'.
Something useful to do if you do not see what you expect is to add extra tempory print statements that simple print a string (something like "you are here") to make sure the code is being run.
I did
I did replace it with 'book' as it was book node type (I just added couple of fields)... Maybe should be custom node, as book would be builtin?
Checking the type
After
add
Then visit a node you think the block should display for. You should see the type print in the message area. If the type is the one in your code add
after the above change. This will show all the fields that are available for printing.
(If the type is not the one you have in the exisiting code, update the code with the type printed and try again)
Did it. First it says: *
Did it. First it says:
* Type is book
Then some code:
But when I do something like:
You guess, it displays just title and "you are here" :(
(no title)
I happened to stumble on the following discussion when karenS (the maintainer of CCK) advices against printing fields in the page template, and suggests printing them only in the node template. But I see that this is not what you want.
http://drupal.org/node/104774
I don't really know why your field is not printed, but they were saying that "the form is wiped out".
A couple of thoughts
Following the link cog.rusty provided try replacing
with
If that does not work try adding
and see what shows.
Thanks
print content_format(field_mycckfield', $node->field_mycckfield[0]); worked! Already quit trying, but was back to this project and needed it. It works, thanks for all your help.
Printing the whole array, not just the first value?
Would like to expand on this a bit. Instead of just printing one value in the array, I'd like to print the whole array.
print content_format('field_keyfeatures', $node->field_keyfeatures[0]) // Prints one value
i.e. Instead of just printing the first key feature (or the second, or whatever the case may be), I'd like to print all key features.
Nevermind, must not be awake yet ...Coffee
Heh, loop through the array with a foreach loop.
Someone should create a
Someone should create a handbook page with the results of this discussion. It solved my issue that I was having with the printer-friendly page module template. I had some CCK fields that were hidden in the node view and needed them to be displayed in the print.tpl.php file. Using the info from this page I got it working perfectly. Thanks guys!