Sorting a collection by the unique Year in a date structure.
  • I would like to sort a collection by year of the end_date so that it only shows a list of unique years. Would something like this work?

    <v:collection path="exhibitions[end_date<now()]" unique="date('Y',end_date)">
    <li><a href=""><v:text path="end_date" strftime="%Y" /></a></li>

  • 3 Answers sorted by
  • Would v:date_selection help you out?

    You can display the unique years from you collection. Onclick, the links that are generated by this tag filter out the results to only show the selected year.

  • Yes! That is just what I needed. thanks you.

    So I had to sort by Year, only showing years which had relevant records with a line break in between, like this

    <a href="#">2011</a>
    <a href="#">2010</a>
    <a href="#">2009</a>
    <a href="#">2008</a>
    <a href="#">2007</a>
    <a href="#">2006</a>
    <a href="#">2005</a>

    So this is what I did:
    <v:date_selection path="exhibitions" date_field="end_date" strftime="%Y">
    <v:divider><br /></v:divider>

  • Awesome!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion