CMS Development

JKeith
Member

Sorting all blog posts

SOLVE

Hi,

 

I was easily able to find a way to sort my blog posts by most recently updated using sort:

{% for content in contents|sort(True, False, 'updatedDateTime') %}

 

However, it only sorts the posts in batches according to the pagination, I guess because of lazy loading? The first page is the 12 most recently published posts sorted by the update time, then the second page is the next 12 most recently published sorted by the update time, and so on.  I tried setting a variable before the loop, as in 

{% set sorted_contents = contents|sort(True, False, 'updatedDateTime') %}

and then pass sorted_contents into the for loop, but it didn't work. 

 

Is there a way to sort the entire contents array outside of pagination/lazy loading? Thanks in advance.

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Sorting all blog posts

SOLVE

Hey @JKeith 

You could use the blog posts API.

Your request could sort parameter to do exactly this!

KevinC_0-1642133896610.png

Ideally this would be returned from a serverless function so the API key isn't exposed.

 

 

EDIT:
This be rather simple using Vue.js!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

View solution in original post

1 Reply 1
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Sorting all blog posts

SOLVE

Hey @JKeith 

You could use the blog posts API.

Your request could sort parameter to do exactly this!

KevinC_0-1642133896610.png

Ideally this would be returned from a serverless function so the API key isn't exposed.

 

 

EDIT:
This be rather simple using Vue.js!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev