Jump to content

Filter repeater results


Olli
 Share

Recommended Posts

Hey

I'm stuck with a issue how to filter repeater results depending on content. I have a few Option fields where you can select "yes", "no" or then leave it blank "". I got my loop working and I'm able to skip content that has not been set. Now I just need a filter for the loop.

<? foreach($pages->get("/content/")->children as $c): ?>
    <div>
        <p>
            <?php if($c->titles) echo $c->titles; ?>
        </p>
    </div>
<? endforeach;?>

I was able to make a if-statement which checked 

if($c->Selector=="no"):

but as it was in the loop, it kinda bugged out. Never got it working either outside the loop...

One really hacky way I thought about was using CSS Classes to set classnames, and that way split what is shown and what is not. This is a really bad way as it still loads all the content for each Selector value.

What I'm looking for is eg. a filter that every Selector with value "yes" will be looped, others dismissed. 

Any ideas how to work on with this?

Edited by Olli
Link to comment
Share on other sites

Hi Olli and welcome!

Sorry, I don't understand the question. Is "titles" your repeater field? What do you want to filter? Can you give an example and your structure?

Cheers

Link to comment
Share on other sites

I edited my post 1 minute before you posted yours Wanze, but I'll give a in-depth explanation.

A loop, or repeater are pages which are repeated according to template and content is according to what is set in the admin section. I simplified my case as if a result is found, I can implement it in a slightly more complex system. I got a Option field to template which gives the values "yes", "no" and "". I would need to find a way to filter the result in the loop.

Lets say I just want the results with value "yes". Then the loop would just show the pages with the value "yes" in the option field.

Another option would be to separate the pages in different child pages, but then again that makes working with it not-so-userfriendly. A filter to either loop throught all contents with "yes" or "no" in field value is what I'm looking for.

Edited by Olli
Link to comment
Share on other sites

To clarify the facts. It seems you're not actually using a repeater, which is a special field in processwire, but you want to filter the pages you're looping over. Is that impression right? In each case you should take a look at the selector docs, which will enable you to filter both repeater field values as well as other lists of pages, like in your loop: http://processwire.com/api/selectors/.

Link to comment
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
 Share

×
×
  • Create New...