Adding an Express EntryList to a Gallery Custom template

Permalink
I'm trying to add a short list of items from am Express entity to a Gallery Slide in a custom template.

Using the documentation herehttps://documentation.concrete5.org/developers/express/creating-read... I can retrieve single entries by ID but the code to retrieve a list of entries seems not to work. Giving the error: Invalid argument supplied for foreach().

<?php 
         $entity = Express::getObjectByHandle('event');      
         $list = new Concrete\Core\Express\EntryList($entity);      
         $results = $list->getResults();
         if ($entity) { 
             foreach($result as $item) { 
                <li><?php echo $item->getEntry()->getEventTitle(); ?></li>
         <?php    }
          } ?>


I'm not sure if this is a bug or if I'm just missing something.

katalysis
 
theana27 replied on at Permalink Reply
theana27
Hi, you have missed "s" in foreach $results.
katalysis replied on at Permalink Reply
katalysis
Thanks @thana27 I got there in the end with this, I was trying to use code that had worked in the Express List block so also had to remove getEntry()-> to make it work.

For anyone else confused here's the working code:

<?php 
$entity = Express::getObjectByHandle('event');
$list = new Concrete\Core\Express\EntryList($entity);
$results = $list->getResults();
if (count($results)) { 
    foreach($results as $item) { ?>
      <li><?php echo $item->getEventTitle(); ?></li>
   <?php }
 }?>