Jekyll - 在滑块中显示图像和文本
Jekyll - show images & text in slider
我正在使用 Bootstrap-Carousel。
不幸的是,来自 front-matter
的数据没有被呈现。
index.html:
...
carousel:
a:
image: home/athenaBeta.jpeg
text: random text 1
b:
image: home/transport.jpeg
text: |
random text 2
c:
image: home/coffee.jpeg
text: |
random text 3
---
{% include hero-carousel.html %}
...
英雄-carousel.html:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
{% capture image %}
{% assign img = news.image %}
{% endcapture %}
<div class="item img-cover img-fixed {% if forloop.index == 0 %}active{% endif %}" style="background-image:url({{ image }})">
<h2>{{ news.text }}</h2>
</div>
{% capture i %}{{ i | plus:1 }}{% endcapture %}
{% endfor %}
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>
它渲染了三张幻灯片,但是 none 的图像或文本被渲染了。我在浏览器中得到的输出如下:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url()">
<h2></h2>
</div>
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>
当您在 page.caroussel
中循环时,您会收到类似这样的信息:
{{ news | inspect }}
==> ["a", {"image"=>"home/athenaBeta.jpeg", "text"=>"random text 1"}]
这是一个包含两个元素的数组。
为了达到你的形象,你可以{% assign img = news[1].image %}
,但你最好重构一下:
...
carousel:
- image: home/athenaBeta.jpeg
text: random text 1
- image: home/transport.jpeg
text: |
random text 2
- image: home/coffee.jpeg
text: |
random text 3
---
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
<div class="item img-cover img-fixed {% if forloop.first %}active{% endif %}" style="background-image:url('{{ news.image }}')">
<h2>{{ news.text }}</h2>
</div>
{% endfor %}
</div>
我正在使用 Bootstrap-Carousel。
不幸的是,来自 front-matter
的数据没有被呈现。
index.html:
...
carousel:
a:
image: home/athenaBeta.jpeg
text: random text 1
b:
image: home/transport.jpeg
text: |
random text 2
c:
image: home/coffee.jpeg
text: |
random text 3
---
{% include hero-carousel.html %}
...
英雄-carousel.html:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
{% capture image %}
{% assign img = news.image %}
{% endcapture %}
<div class="item img-cover img-fixed {% if forloop.index == 0 %}active{% endif %}" style="background-image:url({{ image }})">
<h2>{{ news.text }}</h2>
</div>
{% capture i %}{{ i | plus:1 }}{% endcapture %}
{% endfor %}
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>
它渲染了三张幻灯片,但是 none 的图像或文本被渲染了。我在浏览器中得到的输出如下:
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url(
)">
<h2></h2>
</div>
<div class="item img-cover img-fixed " style="background-image:url()">
<h2></h2>
</div>
</div>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="fa glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="fa glyphicon-chevron-right"></span>
</a>
<a class="arrow-down" href="#content">
<span class="fa glyphicon-chevron-down"></span>
</a>
</div>
当您在 page.caroussel
中循环时,您会收到类似这样的信息:
{{ news | inspect }}
==> ["a", {"image"=>"home/athenaBeta.jpeg", "text"=>"random text 1"}]
这是一个包含两个元素的数组。
为了达到你的形象,你可以{% assign img = news[1].image %}
,但你最好重构一下:
...
carousel:
- image: home/athenaBeta.jpeg
text: random text 1
- image: home/transport.jpeg
text: |
random text 2
- image: home/coffee.jpeg
text: |
random text 3
---
<div id="carousel" class="carousel slide" data-ride="carousel" pause="false">
<div class="carousel-inner text-center">
{% for news in page.carousel %}
<div class="item img-cover img-fixed {% if forloop.first %}active{% endif %}" style="background-image:url('{{ news.image }}')">
<h2>{{ news.text }}</h2>
</div>
{% endfor %}
</div>