Multiple Item Region Filtering

  • I'm trying to filter a multiple item region based on a parameter obtained from the url. Normally this is straightforward, however the parameter is a modified id from the region I'm trying to filter.


    I have a list of services in multiple item region, for the purpose of the example we'll assume each service has only a id of "title":


    Service One

    Service Two

    Service Three


    The first page generates a menu linking to each of the services:


    Code
    1. <p><a href="/services/service-one">Service One</a></p>
    2. <p><a href="/services/service-two">Service Two</a></p>
    3. <p><a href="/services/service-three">Service Three</a></p>

    The sanitise filter takes the id "title" and creates a url friendly version of it using a template filter. This is used to create the href in the link.


    The menu links to a second page which is an index page within the /services directory. This page grabs the end of the url ready to filter the list.


    However as only the santized version of the "title" id is available is it possible to filter the list?


    Is there a way to filter based on a sanitised version of the title id?

  • Woke up this morning and figured it out, remembering a post by the ever helpful hus_hmd.


    Excuse the poor PHP, coding is not my strength.


    I believe the above code creates an array based on the information output by the region. The 'each' function creates an instance of each of the multiple items in the region. The $service variable can be anything, I used $service for clarity (this could be $item, $article, $property - you get the idea).


    To access the title id of each item we put the name of the id in square brackets after the item variable, so my 'title' id can be accessed as:


    $service['title']


    If I wanted the image it would be $service['image'] and so on...


    I manipulated the title using the same technique used to sanitise it for the href and if we get a match to the base name of the url the item is returned.


    When returned it honours the 'page' and 'template' declared in the call.


    I now have a multiple item region that can link to an SEO friendly individual page for each of the items.


    Happy days :-)


    The original post can be found here:

    https://grabapipit.com/blog/re…rder-of-repeaters-content

  • A more efficient way to do this is to add a slug field to your template to create the sanitised version of the title at the point the content is edited. You can then use this slug to create the link and you can filter by it in the usual way.

  • Yeah, I did think of that, and also just using the _id - but using the slug I can't trust the users to keep it url friendly, and not duplicate it - which would lead to me having to sanitise it anyway.


    Using the sanitised title ensures URL (no weird characters) and SEO friendliness and greatly reduces the chances of duplication. A the users don't even have to think about it - which is the goal here.