How to filter related content?

A forum for Bolt related questions / issues

How to filter related content?

Postby daniel » Tue Dec 17, 2013 7:50 pm

Hi Guys

I'm new to the template based possibilities with Twig and Doctrine and have to say it's a pleasure to work with.

But now i have a question:
How can i filter the results of the content.related() Query?
My actual Twig query looks like this and lists all Entries in the actual Page:
Code: Select all
{% set multiplecontent = content.related('entries') %}


Now i need to filter the list of entries by a "filter"-string.
I have no idea how to insert such an additional Query in this.
In SQL i would do something like
Code: Select all
.. AND title LIKE '%searchedword%''


The defined contenttypes:
Code: Select all
pages:
    name: Pages
    singular_name: Page
    fields:
        title:
            type: text
            class: large
            required: true
            index: true
        slug:
            type: slug
            uses: [ title ]
      ...


entries:
    name: Entries
    singular_name: Entry
    fields:
        title:
            type: text
            class: large       
        slug:
            type: slug
            uses: title
    relations:
        pages:
            multiple: false
            order: title
            label: Page


Does anyone has an idea?
daniel
 
Posts: 2
Joined: Tue Dec 17, 2013 7:29 pm

Re: How to filter related content?

Postby Bob » Fri Dec 20, 2013 3:39 pm

With 'set' and '.related()' you can't pass extra query parameters. You can easily filter them when iterating over the results:

Code: Select all
{% for bla in multiplecontent if 'searchedword' in title %}
{{ bla.title }}
{% endfor %}
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: How to filter related content?

Postby daniel » Wed Jan 01, 2014 6:43 pm

Thanks, that's great!

But how to handle this elegant with pagination. The displayed results are in this case not the same like in the query
Code: Select all
{% set multiplecontent = content.related('entries') %}


Tho get the correct amount of entries i have to iterate the whole array and check if the entries matches with the searchword.

Is there a trick to do it more elegant/speed efficient?
daniel
 
Posts: 2
Joined: Tue Dec 17, 2013 7:29 pm

Re: How to filter related content?

Postby Bob » Thu Jan 02, 2014 9:53 am

No, currently there's no really elegant way to do that. I could see someone writing an extension for that, but at the moment you'll have to resort to hackish solutions. :-)
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: How to filter related content?

Postby jadwigo » Sat Jan 25, 2014 7:13 pm

I had a similar problem .. and solved it with an extension (still work in progress)
https://github.com/jadwigo/bolt-photoalbum
My pivotx playground is at http://jivotx.twokings.eu - the rest is at http://www.jadwigo.nl
jadwigo
Developer
 
Posts: 117
Joined: Wed Nov 18, 2009 9:49 am
Location: Den Haag, Netherlands


Return to Bolt Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron