我需要在 jekyll 中按等级排序
I need to order items by rank in jekyll
所以我有一个 table,其中包含机器人锦标赛的分数。
我的google.yml:
teams:
- rank: 1
number: 7854
name: Midnight Madness
qp: 10
rp: 437
plays: 5
- rank: 2
number: 7641
name: MSET Beta Fish
qp: 10
rp: 412
plays: 5
- rank: 3
number: 12804
name: LED
qp: 10
rp: 302
plays: 5
代码是:
---
layout: pastTournaments
title: Google Tournament
permalink: /tournaments/google/
---
<h5 class="column-wrapper centered">These are the rankings for the Google Qualifying tournament, which was hosted on December 2, 2017.</h5>
<br>
<div class="column-wrapper">
<div class="grid-x">
<div class="large-6 shrink cell">
<table>
<thead>
<tr>
<th width="20" class="centered">Rank</th>
<th width="150" class="centered">Team Number</th>
<th width="150" class="centered">Team</th>
<th width="50" class="centered">QP</th>
<th width="50" class="centered">RP</th>
<th width="50" class="centered">Plays</th>
</tr>
</thead>
<tbody>
<!--This is where the jekyll starts-->
{% assign order = 0 %}
{% for team in site.data.google.teams %}
{% assign order = order | plus: 1 %}
{% if team.rank == order %}
<tr>
<td class="centered">{{ team.rank }}</td>
<td class="centered">{{ team.number }}</td>
<td class="centered">{{ team.name }}</td>
<td class="centered">{{ team.qp }}</td>
<td class="centered">{{ team.rp }}</td>
<td class="centered">{{ team.plays }}</td>
</tr>
{% endif %}
{% endfor%}
</tbody>
</table>
</div>
</div>
我需要它,这样当我更改 .yml
文件的等级时它会堆叠,就像我将 1 与 2 和 2 与 1 交换一样。两者就这样消失了:
https://ibb.co/kq0ifR
如何才能在我更改 .yml
文件中的排名时重新排序?
注意:我确实有一些其他不重要的 zurb 东西,这就是为什么这些列没有关闭的原因
您可以使用 sort
液体过滤器。
{% assign sorted = site.data.google.teams | sort:"rank" %}
然后:{% for team in sorted %}
...
所以我有一个 table,其中包含机器人锦标赛的分数。
我的google.yml:
teams:
- rank: 1
number: 7854
name: Midnight Madness
qp: 10
rp: 437
plays: 5
- rank: 2
number: 7641
name: MSET Beta Fish
qp: 10
rp: 412
plays: 5
- rank: 3
number: 12804
name: LED
qp: 10
rp: 302
plays: 5
代码是:
---
layout: pastTournaments
title: Google Tournament
permalink: /tournaments/google/
---
<h5 class="column-wrapper centered">These are the rankings for the Google Qualifying tournament, which was hosted on December 2, 2017.</h5>
<br>
<div class="column-wrapper">
<div class="grid-x">
<div class="large-6 shrink cell">
<table>
<thead>
<tr>
<th width="20" class="centered">Rank</th>
<th width="150" class="centered">Team Number</th>
<th width="150" class="centered">Team</th>
<th width="50" class="centered">QP</th>
<th width="50" class="centered">RP</th>
<th width="50" class="centered">Plays</th>
</tr>
</thead>
<tbody>
<!--This is where the jekyll starts-->
{% assign order = 0 %}
{% for team in site.data.google.teams %}
{% assign order = order | plus: 1 %}
{% if team.rank == order %}
<tr>
<td class="centered">{{ team.rank }}</td>
<td class="centered">{{ team.number }}</td>
<td class="centered">{{ team.name }}</td>
<td class="centered">{{ team.qp }}</td>
<td class="centered">{{ team.rp }}</td>
<td class="centered">{{ team.plays }}</td>
</tr>
{% endif %}
{% endfor%}
</tbody>
</table>
</div>
</div>
我需要它,这样当我更改 .yml
文件的等级时它会堆叠,就像我将 1 与 2 和 2 与 1 交换一样。两者就这样消失了:
https://ibb.co/kq0ifR
如何才能在我更改 .yml
文件中的排名时重新排序?
注意:我确实有一些其他不重要的 zurb 东西,这就是为什么这些列没有关闭的原因
您可以使用 sort
液体过滤器。
{% assign sorted = site.data.google.teams | sort:"rank" %}
然后:{% for team in sorted %}
...