GithubHelp home page GithubHelp logo

Comments (3)

dlitvakb avatar dlitvakb commented on July 28, 2024

Hi @jaybrueder,

There's the sort filter in Liquid, which allows you to sort collections by multiple keys in the objects present within that collection. For example, the following snippet orders a collection of posts by title:

{% for post in site.data.contentful.spaces.blog.posts | sort: 'title' %}
  <h1>{{post.title}}</h1>
{% endfor %}

That said, looks like your data may need some re-structuring, or you need to do some extra looping, as it looks that you're fetching the titles from objects nested in your course_data, and that's not accessible directly through the top level as my example shows.

You can learn more about Liquid filters here: https://help.shopify.com/themes/liquid/filters/array-filters

As for the ID issue, you can access it as if it were a hash key blog_post['123_my_weird_key'] instead of using the dot notation.

Cheers

from jekyll-contentful-data-import.

jaybrueder avatar jaybrueder commented on July 28, 2024

Thank you for your help!

Organising the data into one YAML file makes this problem go away.
I am sorting the data like this now. Works like a charm.

{% assign sorted = site.data.contentful.spaces.company.course | sort: 'title' %}
      
{% for topic_data in sorted %}
   {% assign title = topic_data['title'] %}
   {% assign subheadline = topic_data['subheadline'] %}
      
   {% include course.html title=title subheadline=subheadline %}
{% endfor %}

from jekyll-contentful-data-import.

dlitvakb avatar dlitvakb commented on July 28, 2024

That's great! Glad it worked out.

Cheers

from jekyll-contentful-data-import.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.