3 ways to sort your content pages entries

Carlos Solis

Carlos Solis

The new content pages can display content in just a couple of clicks with virtually no additional code. This powerful tool allows us to display data, create paths, and automatically classify information.

Content pages can modify the look and feel of your websites and even perform advanced processes on the data displayed, such as, filtering or sorting according to custom categories.

Sorting records is a standard and valuable process for users because it allows them to know which are the most recent records or highlight information automatically, so let's learn three different ways to organize the entries of a content page.

All the properties we use here - and many more! -  are available in the "Entry Attributes" dropdown of your content page.



1-Sort by creation date

Let's start here by using the code that is automatically generated in the index template when creating a content page:

Entry Attributes ScreenshotImage Caption

As we can see here, we have a value called "entries", which contains an array or list that contains all the entries defined when creating the content page.

To order a specific list, we must assign it a new variable, which means we have to make two minimal changes in the code. The first is to create where it will be stored sorted like this:

Entry Attributes Screenshot

This variable contains all the sorted records, and we need to display them inside the HTML.

The next step is to update the loop to use this new variable.

That's it! Now the information will be displayed sorted by date of publication.


2-Sort by update date

Sorting a list by update date can help to keep the latest, content on top, the process in this case, use the same code but replaces the value of "sort_by" to "updated_at".

Let's take the opportunity to examine the fields, "sort_by" is an order filter and has two values; the first is the selection criteria, the second is the order, which can be ascending ("asc") or descending ("desc").

3- Sort by alphabetical order

The third and last option is great for product catalogs or long datasets that need quick browsing, and now that we know the code and the syntax, this last option is the easiest to learn. We only need to change the order property to "name".

Conclusion

Content pages are quick and easy to use, but with a couple of extra lines of code we can take it further to customize the experience. 

You can find more information about the Liquid syntax in Modyo Docs



Photo by Andre-taissin via unsplash

Other Developer Tips

Architecture
Carlos Solís

Carlos Solís

Domain Driven Design: How to Implement a Scalable Architecture for Your Business

Learn how Domain Driven Design (DDD) empowers you to build applications that align with your business. Apply DDD in microservices and micro frontends architectures to create scalable,and maintainable solutions,leveraging the power of Modyo.

Carlos Solís

Carlos Solís

Instant Image Optimization with Liquid in Modyo

Optimizing images is essential for any website, especially if you’re aiming for fast load times and a great user experience.

Customers
Carlos Solís

Carlos Solís

Creating Forms in Modyo

Forms are fundamental in any financial application. They help capture critical user information, such as personal data, preferences, and financial details.