Jump to content

Recommended Posts

Posted

I was previously using individual fields to capture and output multiple cards onto my web page but after recently learning about repeaters would prefer to use this field type, as it will be a lot more user friendly for end users to create new cards. I tried to modify my code to grab the fields from the new Repeater field(s) but am getting this error message on the page:

Quote

: foreach() argument must be of type array|object, null given in C:\xampp\htdocs\dccdp\site\assets\cache\FileCompiler\site\templates\projects.php on line 27

Here is the code I'm currently trying to use for the cards:

<?php
// https://processwire.com/api/arrays/
// check if the array of images has items
foreach($page->tall_card as $card) {
  $count = 0;
  $count++;
  $options = array( 'quality' => 70 );
  $image = $card->image;
  $img = $card->image->size(550, 400, $options);
  $cardHeading = $card->title;
  $cardBody = $card->plain_paragraph;
  $raised = $card->raised_amount;
  $goal = $card->goal_amount;
  $link = $card->link;

  if ($raised == 0 ) :
  $percent = 0;
  else:
  $percent = $raised_amount / $goal_amount * 100;
  endif;

  if ($percent <= 5) :
  $percent = 0;
  endif;
?>

<span id="card<?php echo $count?>" class="card">

  <img class="cardThumb" src="<?php echo $img->url; ?>" alt="<?php echo $image->description; ?> Thumbnail" />

  <div class="cardBody">

    <div class="cardText">
      <h2><?php echo $cardHeading; ?></h2>
      <?php echo $cardBody; ?>
    </div>

    <div class="progressBarSection">
      <progress class="progressBar" id="progressbar<?php echo $count; ?>" value="<?php echo $percent; ?>" max="100"></progress>
      <span class="raisedAmount">
        $<?php echo $raised; ?> usd
      </span>
      <span class="goalAmount">
        $<?php echo $goal; ?> usd
      </span>
    </div>

    <div class="primaryBtn">
      <a href="https://www.paypal.com/donate?hosted_button_id=
               <?php echo $link; ?>
               &source=url">
        <button>
          <i class="fas fa-donate"></i> Donate
        </button>
      </a>
    </div>

  </div>

</span>

<?php
}
?>

Thanks in advance for any help!

  • spercy16 changed the title to Having trouble getting the Repeater field to output my cards.
Posted (edited)

Hi @spercy16!

Are you super sure tall_card is the name of your repeater field? It seems to be a non existent object. 

Edited by elabx
typo
Posted

Is the repeater set in the projects template? Maybe a screenshot of your template/repeater field config could help!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...