Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Nunjacks图标计数宏_Javascript_Html_Templates_Nunjucks - Fatal编程技术网

Javascript Nunjacks图标计数宏

Javascript Nunjacks图标计数宏,javascript,html,templates,nunjucks,Javascript,Html,Templates,Nunjucks,我正在使用Nunjucks,希望创建一个加上星形图标的宏,然后在模板中,我可以指定每个元素有多少颗星:例如: {{star(4)}} 将显示图标星: 评级:**** 评级:***** 目前我不知道如何通过计数: {% macro starIconTables( star ) %} {% for star in stars %} <span class="icon icon-star-filled"></span> {% endfor %

我正在使用Nunjucks,希望创建一个加上星形图标的宏,然后在模板中,我可以指定每个元素有多少颗星:例如:

{{star(4)}}
将显示图标星:

评级:****

评级:*****

目前我不知道如何通过计数:

{% macro starIconTables( star ) %}

    {% for star in stars %}
        <span class="icon icon-star-filled"></span>
    {% endfor %}

{% endmacro %}
{%macro starIconTables(star)%}
{stars%%中的星为%s}
{%endfor%}
{%endmacro%}

您可以使用
范围

{% macro stars(num) %}
{%- for i in range(0, num) -%}<span class="icon icon-star-filled"></span>{%- endfor -%} 
{% endmacro %}

stars: {{ stars(4) }}
stars: {{ stars(10) }}
{%macro stars(num)%}
{%-fori在范围(0,num)-%}{%-endfor-%}
{%endmacro%}
星星:{{星星(4)}
星星:{{星星(10)}
p.S.
{%-
-%}
移除额外的线路断路器