Jump to content
a-ok

Return rows of a repeater if a select field matches...

Recommended Posts

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

Share this post


Link to post
Share on other sites

Try:

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

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By carlitoselmago
      It's been twice this year as a PW developer where clients have asqued me to have a way to put content on specific coordinates of a picture. Something like what image maps are made of. But not necesarly on links, sometimes text, sometimes images and links. 
      So I've been thinking to build an inputfield for that purpose. But I'm not sure how could it be the most flexible so I can share it in github/modules page.
      Ideally it would need to work like a repeater field where you start uploading an image and then adding any custom field like title, url etc. So the user could add multiple elements floating over that image.
      Does anybody here know the ideal way to start the arquitecture of something like that? I could just hardcode the fields I need for the website I have to code this month but it would be nice to be something more flexible.
    • By fruid
      how to get all the subfields of a repeater field generically? I'm not talking about a specific field that I know the name of, that's easy, I'm trying to access them in general in the $fields variable itself.
      Better yet, how to access them by type?
    • By picarica
      so i made some options in t he field type, and i want to check if selected title is that output this is my sample code
      if($media->r_soc == 'facebook') { $soc = 'facebook'; } elseif($media->r_soc == 'twitter') { $soc = 'twitter'; } i just basically want to check if the user in CMS selected option facebokk and then outpit it into variable which is later outputted into fa icon, oh and also this is all in repeat field
      foreach($ikonky as $media) { so thats why its $media, but as of now it outputs blank state, not sure why,
      it doesnt outpit anything none of the check goes throught these are options i have in the field
      1=facebook 2=twitter 3=instagram 4=youtube 5=github 6=linkedin  
    • By David Karich
      ProcessWire InputfieldRepeaterMatrixDuplicate
      Thanks to the great ProModule "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use a content module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      This module extends the commercial ProModule "RepeaterMatrix" by the function to duplicate repeater items from one page to another page. The condition is that the target field is the same matrix field from which the item is duplicated. This module is currently understood as proof of concept. There are a few limitations that need to be considered. The intention of the module is that this functionality is integrated into the core of RepeaterMatrix and does not require an extra module.
      Check out the screencast
      What the module can do
      Duplicate multible repeater items from one page to another No matter how complex the item is Full support for file and image fields Multilingual support Support of Min and Max settings Live synchronization of clipboard between multiple browser tabs. Copy an item and simply switch the browser tab to the target page and you will immediately see the past button Support of multiple RepeaterMatrix fields on one page Configurable which roles and fields are excluded Configurable dialogs for copy and paste Duplicated items are automatically pasted to the end of the target field and set to hidden status so that changes are not directly published Automatic clipboard update when other items are picked Automatically removes old clipboard data if it is not pasted within 6 hours Delete clipboard itself by clicking the selected item again Benefit: unbelievably fast workflow and content replication What the module can't do
      Before an item can be duplicated in its current version, the source page must be saved. This means that if you make changes to an item and copy this, the old saved state will be duplicated Dynamic loading is currently not possible. Means no AJAX. When pasting, the target page is saved completely No support for nested repeater items. Currently only first level items can be duplicated. Means a repeater field in a repeater field cannot be duplicated. Workaround: simply duplicate the parent item Dynamic reloading and adding of repeater items cannot be registered. Several interfaces and events from the core are missing. The initialization occurs only once after the page load event Attention, please note!
      Nested repeaters cannot be supported technically. Therefore a check is made to prevent this. However, a nested repeater can only be detected if the field name ends for example with "_repeater1234". For example, if your MatrixRepeater field is named like this: "content_repeater" or "content_repeater123", this field is identified as nested and the module does not load. In version 2.0.1 the identification has been changed so that a field ending with the name repeater is only detected as nested if at least a two-digit number sequence follows. But to avoid this problem completely, make sure that your repeater matrix field does NOT end with the name "repeater".
      Changelog
       
      2.0.1
      Bug fix: Thanks to @ngrmm I could discover a bug which causes that the module cannot be loaded if the MatrixRepeater field ends with the name "repeater". The code was adjusted and information about the problem was provided 2.0.0
      Feature: Copy multiple items at once! The fundament for copying multiple items was created by @Autofahrn - THX! Feature: Optionally you can disable the copy and/or paste dialog Bug fix: A fix suggestion when additional and normal repeater fields are present was contributed by @joshua - THX! 1.0.4
      Bug fix: Various bug fixes and improvements in live synchronization Bug fix: Items are no longer inserted when the normal save button is clicked. Only when the past button is explicitly clicked Feature: Support of multiple repeater fields in one page Feature: Support of repeater Min/Max settings Feature: Configurable roles and fields Enhancement: Improved clipboard management Enhancement: Documentation improvement Enhancement: Corrected few typos #1 1.0.3
      Feature: Live synchronization Enhancement: Load the module only in the backend Enhancement: Documentation improvement 1.0.2
      Bug fix: Various bug fixes and improvements in JS functions Enhancement: Documentation improvement Enhancement: Corrected few typos 1.0.1
      Bug fix: Various bug fixes and improvements in the duplication process 1.0.0
      Initial release Support this module
      If this module is useful for you, I am very thankful for your small donation: Donate 5,- Euro (via PayPal – or an amount of your choice. Thank you!)
      Download this module (Version 2.0.1)
      > Github: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate
      > PW module directory: https://modules.processwire.com/modules/inputfield-repeater-matrix-duplicate/
      > Old stable version (1.0.4): https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate/releases/tag/1.0.4
    • By arnd
      Hi,
      I have a repeater with some images in it.
      As Superuser I can work with the Actions (rotate...). But my Users with lower Rights can't use this Actions.
      The same User can use the Actions on images outsite a Repeter-Field. So I think it's not a Problem of Rights-Management but from Images in Repeater Fields.
      ProcessWire 3.0.164.  Bug? Or can I manage this in the settings?
      Thanks in advance
×
×
  • Create New...