Running Drupal 5.1
CCK 5.x-1.3
MySQL 5 (running in MSQL40 mode)
PhP5
IIS6

I'm getting "warning: Invalid argument supplied for foreach() in ..\MyTheme\node-test.tpl.php on line 10.

I copied the content of \modules\cck\theme\template.php (1 function) in my theme's template.php file.

When I try to return just one (custom) field value, it doesn't return anything. When I try to make use of the foreach loop supplied in node-test.tpl.php (test being the name of my custom content type) , I get the warning, and no value is being returned to the page.

Thanks
Charles

Comments

yched’s picture

the cck template.php function only comes into play if you use field-specific templates (field.tpl.php), but is out of the loop for node templates.
You should probably post the content of your node-test.tpl.php file.

forgestik’s picture

All right. First, here's what I get when I run the function allowing me to list all the available variables...

Submitted by Charles G.C. on Fri, 03/02/2007 - 16:18.
stdClass Object ( [nid] => 60 [vid] => 61 [type] => test [status] => 1 [created] => 1172852286 [changed] => 1172852343 [comment] => 0 [promote] => 1 [sticky] => 0 [revision_timestamp] => 1172852343 [title] => Test number 2 [teaser] => And this is the teaser of my test story [log] => [format] => 4 [uid] => 11 [name] => Charles G.C. [picture] => [data] => a:0:{} [field_ppicture] => Array ( [0] => Array ( [fid] => 0 [title] => [alt] => [view] => ) ) [field_ttext_0] => Array ( [0] => Array ( [value] => Default Value [format] => 4 [view] =>

Default Value
) [1] => Array ( [value] => text value 2 [format] => 4 [view] =>

text value 2
) [2] => Array ( [value] => text value 3 [format] => 4 [view] =>

text value 3
) [3] => Array ( [value] => text value 4 [format] => 4 [view] =>

text value 4
) ) [iid] => [taxonomy] => Array ( ) [files] => Array ( ) [readmore] => [content] => Array ( [field_ttext_0] => Array ( [#access] => 1 [#value] => [#weight] => 0 [#printed] => 1 ) [field_ppicture] => Array ( [#access] => 1 [#value] => [#weight] => 0 [#printed] => 1 ) [body] => Array ( [#weight] => 0 [#value] =>

This is the body content of my story.
Here are more lines
line 2
line 3
line 4
[#printed] => 1 ) [#children] =>

This is the body content of my story.
Here are more lines
line 2
line 3
line 4
[#printed] => 1 ) [links] => Array ( ) [nodeteaser] => 1 ) 
forgestik’s picture

When running the code below, I'm getting no result, but no warning message

<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) {
      print $picture;
    }?>
    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
    <span class="submitted"><?php print $submitted?></span>
    <span class="taxonomy"><?php print $terms?></span>
    <div class="content">
       <!-- this snippet here doesn't return any result -->
        <?php print $field_ttext[0]['view']; ?>
        
    </div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
  </div>
forgestik’s picture

And finally, this loop below is returning a warning message (see title of this issue) and no results.

      <?php
        foreach ($field_ttext as $item) {
          print '<li>'. $item['view'] .'</li>';
        }
      ?>
yched’s picture

Status: Active » Fixed

closing support request - please reopen if needed

killes@www.drop.org’s picture

Status: Fixed » Closed (fixed)