将变量传递给标签 Jekyll
Pass variable into for tag Jekyll
简而言之
如何将此赋值变量放入 for 标记中?
{% assign thisslider = include.whichslider %} // returns "slider1"
{% for item in thisslider %}
上下文
在我的博客网站上,我正在努力实现 post 图片通过滑块显示在文章中。
它只适用于一个滑块,但是当我想要多个滑块时,我希望能够指定包含哪个滑块;
{% include content-slides.html whichslider="slider1" %}
在 content-slides.html 中,我需要获取包含参数 "slider1" 并将其传递到 for 循环声明中,如下所示;
{% assign thisslider = include.whichslider %}
{% for item in page.thisslider %}
<p>each slide code in here</p>
{% endfor %}
</div>
因此 for 循环遍历 include 参数中定义的滑块(在 post 前文中引用)
post.md
---
layout: default
slider1:
item1 :
image : "xe-1.jpg"
alt : "foo"
caption : "this is the caption"
item2 :
image : "xe-2.jpg"
alt : "foo"
caption : "this is the caption for second slide"
slider2:
item1 :
image : "xe-3.jpg"
alt : "foo"
caption : "this is the caption"
item2 :
image : "xe-4.jpg"
alt : "foo"
caption : "this is the caption for second slide"
---
{% include content-slides.html whichslider="slider1" %}
{% include content-slides.html whichslider="slider2" %}
内容-slides.html
{% assign thisslider = include.whichslider %}
{% for item in page.thisslider %}
<p>each slide code in here</p>
{% endfor %}
替换点符号:
{% for item in page.thisslider %}
括号表示法
{% for item in page[thisslider] %}
简而言之
如何将此赋值变量放入 for 标记中?
{% assign thisslider = include.whichslider %} // returns "slider1"
{% for item in thisslider %}
上下文
在我的博客网站上,我正在努力实现 post 图片通过滑块显示在文章中。 它只适用于一个滑块,但是当我想要多个滑块时,我希望能够指定包含哪个滑块;
{% include content-slides.html whichslider="slider1" %}
在 content-slides.html 中,我需要获取包含参数 "slider1" 并将其传递到 for 循环声明中,如下所示;
{% assign thisslider = include.whichslider %}
{% for item in page.thisslider %}
<p>each slide code in here</p>
{% endfor %}
</div>
因此 for 循环遍历 include 参数中定义的滑块(在 post 前文中引用)
post.md
---
layout: default
slider1:
item1 :
image : "xe-1.jpg"
alt : "foo"
caption : "this is the caption"
item2 :
image : "xe-2.jpg"
alt : "foo"
caption : "this is the caption for second slide"
slider2:
item1 :
image : "xe-3.jpg"
alt : "foo"
caption : "this is the caption"
item2 :
image : "xe-4.jpg"
alt : "foo"
caption : "this is the caption for second slide"
---
{% include content-slides.html whichslider="slider1" %}
{% include content-slides.html whichslider="slider2" %}
内容-slides.html
{% assign thisslider = include.whichslider %}
{% for item in page.thisslider %}
<p>each slide code in here</p>
{% endfor %}
替换点符号:
{% for item in page.thisslider %}
括号表示法
{% for item in page[thisslider] %}