Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Custom ordering in for loop

Started by Muut Archive 11 years ago · 2 replies · 382 views
11 years ago

Hi there, I have page where I'm displaying list of github libs like this:
-```
{% for p in page.find('/libraries').header.libraries %}
<div class="category_item">
<h2><a href="{{ p.link }}">{{ p.title }}</a></h2>
{{ p.description|markdown }}
</div>
{% endfor %}

TXT

libraries are stored in .md file like this:

libraries:

I've found that I can easily show stars of particular library like this:

TWIG
{{ github.client.api('repo').show('getgrav', 'grav')['stargazers_count'] }}

How can I order my list of libraries based on stars of each library?

11 years ago

You probably need to build a plugin to do that. That plugin should listen for the onPageInitialized event, get the libraries from the page header, get the stargazers count from GitHub, then reorder and make the new object available to be used in the page.

11 years ago

Yeah, I was afraid there won't be easier solution, I guess I'll have to learn plugins then :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1118 9 years ago