如何在 Jekyll 中多次重复字符串?
例如:在 Python 中,您可以"hello" * 5
获取'hellohellohellohellohello'
. 在 Jekyll 中有比这更简单的方法来做同样的事情。
{% for i in (1..5) %}
Hello
{% endfor %}
例子
假设您要显示星级,并且您正在使用<i class="fa fa-star"></i>
来显示每颗星。因此,要显示 5 星评级,您会这样做。
{% for i in (1..5) %}
<i class="fa fa-star"></i>
{% endfor %}
单个页面上可能显示了许多评级,因此您将使用该 for 循环的多个实例。