Selecting and sorting pages by data form fields

by michal frackowiak on 28 Dec 2011 12:59

Last week I wrote that we had a feature release planned for the holiday season. Some of you guessed it would be data forms support in the ListPages module. Looking at the top wishes it was quite a probable guess, and it was correct!

We have just deployed the improved version of ListPages with support for selecting pages by custom fields defined via data forms. We have chosen a simple syntax for querying but we are already thinking about extending it and adding more operators. The today's release should however provide you tools to play with and test our implementation.

Take a look at an example. Suppose we have a "band" category populated with entries for music bands defined by the data form:

[[form]]
fields:
  type:
    label: Music type
    type: select
    values:
      0: Classical
      1: Country
      2: Folk
      3: Indie
      4: Jazz
      5: Pop
      6: Rock
    default: 6
  bandwebsite:
    label: Band website
    type: url
  rating:
    label: My rating
    type: select
    values:
      0: Terrible
      1: I have seen worse
      2: Better than Justin Bieber
      3: Got used to it
      4: Cool
      5: Awesome
      6: Cannot live without it
[[/form]]

Now, to select music bands that only play folk we can use:

[[module ListPages category="band" _type="2"]]
<format>
[[/module]]

Note the underscore in front of the selection parameter — it denotes that the field is a custom one, defined by the data form.

You can mix several selection parameters, both custom fields and all previously supported ones. Criteria will be joined by the and operator, as previously.

Custom fields can be also used for sorting. To sort all bands by rating starting from the best to worst we can use:

[[module ListPages category="band" order="_rating desc"]]

That's it! We will update the documentation later on, but the above examples show it all.

Now here is a word of warning. Although this feature looks like a piece of cake, it was not that easy to implement. We hope it will work well for your sites (we have put it through thorough tests), but please treat it as a "beta" which can be changed or even pulled back if we discover serious issues.

Performance might not be super-stellar but is sufficient for sets up to thousands pages. We will work on improvements once we receive more feedback. Until then please use data form selectors on large categories carefully, especially when using multiple modules on a single page.

I hope you will like this new feature. What's more important, I believe it will enable you to build even greater sites and applications. Take care!

Comments: 13

Add a New Comment