I am using contemplate on my site.
On some pages, this error message might appear:

warning: Invalid argument supplied for foreach() in /home/activ41/public_html/site/sites/all/modules/contemplate/contemplate.module(765) : eval()'d code on line 66.

In my contemplate, I am using the following foreach command:

<div class="course_page_block">
<h2 class="lc"> Syllabus Materials</h2>
<ul class="rc">
<?php
<?php foreach($node->field_link_to_support as $delta => $field) : ?>
      <?php if ($node->field_link_to_support as $delta => $field): ?>
      <h2><?php print '<li> Link: '.$node->field_link_to_support[$delta]['view'].'</li>';?></ul>
      <?php endif; ?>
</div>

I can't see anything wrong with the code that should cause the error message to appear.

I know that Contemplate 5x is no longer supported, but I was wondering if someone could give me some pointers.

Comments

jrglasgow’s picture

you get the "Invalid argument supplied for foreach()" error when the variable $node->field_link_to_support is not of a type that can be used (object or array) or the variable $node->field_link_to_support is empty

I would try

<div class="course_page_block">
<h2 class="lc"> Syllabus Materials</h2>
<ul class="rc">
<?php if (!empty($node->field_link_to_support)) : ?>
  <?php foreach($node->field_link_to_support as $delta => $field) { ?>
      <?php if ($node->field_link_to_support as $delta => $field): ?>
      <h2><?php print '<li> Link: '.$node->field_link_to_support[$delta]['view'].'</li>';?></ul>
      <?php endif; ?>
  <?php } ?>
<?php endif; ?>
</div>
littly_kitty’s picture

Thanks for your help!

When I try that code I get an unexpected T_AS error.
I have had a careful look at the code, but I can't see anything wrong. (Other than the stray <H2> tag, 5 lines up from the bottom)

I'm really not sure what I am doing wrong, so any help would be appreciated.