我需要在jekyll中按排名订购商品

时间:2017-12-15 06:17:28

标签: html zurb-foundation jekyll liquid

所以我有一张桌子上有机器人锦标赛的分数。

我的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

https://ibb.co/dtc776

代码是:

---
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东西,这就是为什么列没有关闭

1 个答案:

答案 0 :(得分:1)

您可以使用sort液体过滤器。

{% assign sorted = site.data.google.teams | sort:"rank" %}

然后:{% for team in sorted %} ...