Jump to content

Recommended Posts

Posted

Hi folks,

I have a repeater set up on a page and wondered if it's possible to only return the repeater rows that have a certain 'item' selected from a dropdown select field? So, for example, on my dropdown select I have two options 1: Article and 2: Sector guide, and I can return each row of the repeater easily enough with:

<?php $articles = $pages->get('/practice/publications/'); ?>

<?php foreach ($articles->practice_publication as $article) : ?>
    <?php echo $article->practice_publication_title; ?>
<?php endforeach; ?>

But this will of course return all the repeater fields, whereas I need it to only return the fields which have the practice_publication_type=1, for example. I tried looking around for the answer to this but couldn't find anything. Maybe it's not possible...

Cheers,

R

Posted

Try:

<?php foreach ($articles->practice_publication->filter('practice_publication_type=1') as $article) : ?>
Posted

Thanks for your reply, diogo. This seemed to have worked for my top query, but it has also affected my bottom query to return the same thing?

<?php $guides = $pages->get('/practice/publications/'); // Sector Guides ?>
<div class="container-fluid">
<div class="row">
  <div class="col-xs-12 col-sm-12">
   <h2 class="publications-type-subtitle">Sector Guides</h2>
  </div>
</div>
<div class="row">
  <div class="publication-container guide">
   <?php foreach ($guides->practice_publication->filter('practice_publication_type=2') as $guide) : ?>
    <div class="each-publication guide">
     <?php if (count($guide->practice_publication_image)) : ?>
     <?php $resized = $guide->practice_publication_image->width(400); ?>
     <div class="image-container">
      <a href="<?php echo $guide->practice_publication_download->url; ?>">
       <img class="lazy loading" src="<?php echo $config->urls->templates; ?>img/1x1.gif" data-original="<?php echo $resized->url; ?>" data-medium="<?php echo $resized->url; ?>" />
      </a>
     </div>
     <div class="text-container">
      <p><?php echo $guide->practice_publication_title; ?></p>
     </div>
     <?php endif; ?>
    </div>
   <?php endforeach; ?>
  </div>
</div>
</div>
<?php $articles = $pages->get('/practice/publications/'); // Articles ?>
<div class="container-fluid">
<div class="row">
  <div class="col-xs-12 col-sm-12">
   <h2 class="publications-type-subtitle">Articles</h2>
  </div>
</div>
<div class="row">
  <div class="publication-container article">
   <?php foreach ($articles->practice_publication as $article) : ?>
    <div class="each-publication article">
     <?php if (count($article->practice_publication_image)) : ?>
     <?php $resized = $article->practice_publication_image->width(400); ?>
     <div class="image-container">
      <a href="<?php echo $article->practice_publication_download->url; ?>">
       <img class="lazy loading" src="<?php echo $config->urls->templates; ?>img/1x1.gif" data-original="<?php echo $resized->url; ?>" data-medium="<?php echo $resized->url; ?>" />
      </a>
     </div>
     <div class="text-container">
      <p><?php echo $article->practice_publication_title; ?><?php if ($article->practice_publication_date) : ?> <?php echo $article->practice_publication_date; ?><?php endif; ?></p>
     </div>
     <?php endif; ?>
    </div>
   <?php endforeach; ?>
  </div>
</div>
</div>

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...