是否可以在单个include中包含多个参数?
单个参数:
{% include card.html class=include.class1 %}
多个参数怎么办?
{% include card.html class=include.class1 class2=include.class2 %}
还是我需要这样做:class1=include.class1 class2=include.class2?
是否可以在单个include中包含多个参数?
单个参数:
{% include card.html class=include.class1 %}
多个参数怎么办?
{% include card.html class=include.class1 class2=include.class2 %}
还是我需要这样做:class1=include.class1 class2=include.class2?
可以通过在空格param1=value1 param2=value2
之间传递多个include参数,例如:
{% include image.html url="http://jekyllrb.com"
max-width="200px" file="logo.png" alt="Jekyll logo"
caption="This is the Jekyll logo." %}
然后你可以通过前缀为include.
的方式在包含文件中使用它们,例如:
{{include.file}} {{include.caption}}
正如@marcanuy所说,
一种方法是使用capture函数将多个值包含在单个参数中。
{% capture classes %} {{include.class1}} {{include.class2}} {% endcapture %}
{% include card.html class=classes %}
<label>{{include.label}}</label>
{% for option in include.options %}
<input type="radio" name="{{include.label}}" id="{{include.option}}" value="{{include.option}}" checked="checked"/><label for=" {{include.option}}">{{include.option}}</label>
{% endfor %}
你可以这样调用:
{% include radiobuttons.html label="favorite color" options="green", "blue", "orange", "red" %}