Jekyll 中多次重复字符串

Ish*_*han 5 templating-engine liquid static-site jekyll

如何在 Jekyll 中多次重复字符串?

例如:在 Python 中,您可以"hello" * 5获取'hellohellohellohellohello'. 在 Jekyll 中,有比这更简单的方法来做同样的事情吗?

{% for i in (1..5) %}
  Hello
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

例子

假设您想要显示星级,并且您正在使用它<i class="fa fa-star"></i>来显示每颗星。因此,要显示 5 星评级,您就可以这样做。

{% for i in (1..5) %}
    <i class="fa fa-star"></i>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

单个页面上可能会显示许多评级,因此您将使用该 for 循环的多个实例。

But*_*uts 0

这是最好的办法。

如果您关心的是性能;那么你不需要担心,因为 Jekyll Liquid 无论如何都会被预编译成 html,所以性能只会在构建时受到影响。