i would like to add a node with a php snipplet getting a cck field value and passing it as argument to a view;

the cck field is named field_luogo, so i've tried

$node->field_luogo[0]['value'];

but i get no value

is this the right way ?

Comments

scoorch’s picture

Try to print the $node once you have loaded it and analyse the content of the $node object. Then you can see if the value is there and the way you try to access it is correct.

you can use the following code to print the node object

drupal_set_message('Node object: '. print_r($node));

If you have the devel module and are the admin you can also use dprint_r instead of print_r

Hope this helps.

sbrodolo’s picture

thanks
i've already tried print_r($node) , but i get no output

then i've tried to put the print_r($node) in the node-typeofcontent.tpl.php (previously i've put php code in body of node, after enabling php input filter)
this time it worked fine and i was able to read the cck field

is there some reason why i cannot read field putting the code in the node body ?

pierluigi

scoorch’s picture

or an extract of it

sbrodolo’s picture

here the tempalte file ( i'm using zen theme)

latrina@supposta:/var/www/drupal/sites/all/themes/sweetitaliazen$ cat node-acctractions.tpl.php

// $Id: node.tpl.php,v 1.4 2008/09/15 08:11:49 johnalbin Exp $

/**
 * @file node.tpl.php
 *
 * Theme implementation to display a node.
 *
 * Available variables:
 * - $title: the (sanitized) title of the node.
 * - $content: Node body or teaser depending on $teaser flag.
 * - $picture: The authors picture of the node output from
 *   theme_user_picture().
 * - $date: Formatted creation date (use $created to reformat with
 *   format_date()).
 * - $links: Themed links like "Read more", "Add new comment", etc. output
 *   from theme_links().
 * - $name: Themed username of node author output from theme_user().
 * - $node_url: Direct url of the current node.
 * - $terms: the themed list of taxonomy term links output from theme_links().
 * - $submitted: themed submission information output from
 *   theme_node_submitted().
 *
 * Other variables:
 * - $node: Full node object. Contains data that may not be safe.
 * - $type: Node type, i.e. story, page, blog, etc.
 * - $comment_count: Number of comments attached to the node.
 * - $uid: User ID of the node author.
 * - $created: Time the node was published formatted in Unix timestamp.
 * - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
 *   teaser listings.
 * - $id: Position of the node. Increments each time it's output.
 *
 * Node status variables:
 * - $teaser: Flag for the teaser state.
 * - $page: Flag for the full page state.
 * - $promote: Flag for front page promotion state.
 * - $sticky: Flags for sticky post setting.
 * - $status: Flag for published status.
 * - $comment: State of comment settings for the node.
 * - $readmore: Flags true if the teaser content of the node cannot hold the
 *   main body content.
 * - $is_front: Flags true when presented in the front page.
 * - $logged_in: Flags true when the current user is a logged-in member.
 * - $is_admin: Flags true when the current user is an administrator.
 *
 * @see template_preprocess()
 * @see template_preprocess_node()
 */
print $node->nid; " class=" print $classes; ">

print $picture;

if (!$page):

print $node_url; " title=" print $title "> print $title;

endif;

if ($unpublished):

print t('Unpublished');

endif;

if ($submitted or $terms):

if ($submitted):

endif;

if ($terms):

print t(' in ') . $terms;

endif;

endif;

print $content;

<? $ag=$node->field_loco[0]['view'];
$viewName = 'strutture';
$display_id = 'page';
print views_embed_view($viewName, $display_id, $ag);

?>
print $links;