如何在我的Jekyll网站上的模式中放置多个图像?

时间:2017-01-11 19:26:54

标签: twitter-bootstrap jekyll bootstrap-modal jekyll-bootstrap

我正在使用修改后的Bootstrap主题(specifically this theme)和Jekyll完成构建网站。这是我第一次使用Jekyll,到目前为止,情况一直很顺利,直到这一点让我感到难过。

就像我上面链接的bootstrap主题一样,我有一个投资组合部分,打开了一个模式,我想要包含一些照片和段落的文本。到目前为止,我有模态帖子的其他元素以我想要的方式工作,但无法想出添加多个图像的方法。

这是我的投资组合模式的html

{% for post in site.posts %}
<div class="portfolio-modal modal fade" id="portfolioModal-{{     post.modal-id }}" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="close-modal" data-dismiss="modal">
            <div class="lr">
                <div class="rl">
                </div>
            </div>
        </div>
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2">
                    <div class="modal-body">
                        <!-- Project Details Go Here -->
                        <h2>{{ post.title }}</h2>
                        <p class="item-intro text-muted"> {{   post.subheading }} </p>
                        <p>{{ post.description }}</p>
                        <img class="img-responsive" src="img/portfolio/{{ post.img }}">
                        <ul class="list-inline">
                            <li>Date: July 2014</li>
                            <li>Location: {{ post.location }} </li>
                            <li>Category: {{ post.category }} </li>
                        </ul>
                        <button type="button" class="btn btn-primary"  data-dismiss="modal"><i class="fa fa-times"></i> Close Project</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
{% endfor %}

这是我的模态帖子的前沿问题

---
layout: post
modal-id: 1
title:  Post title
date:   2017-01-06
location: Project location
img: img.jpg
category: Post category
alt: image-alt
description: Post description
---

所以,我不确定如何为每个帖子添加多个图像。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

构建序列/数组/图像列表和alt标记以替换img:&amp; Front Matter 中的alt:然后循环遍历它们。没什么别的。

示例序列:

images-array:
 - image: image-1.jpg
   alt: This is some alt text
 - image: image-2.jpg
   alt: This is some alt text
 - image: image-3.jpg
   alt: This is some alt text

更新了前言:

---
layout: post
modal-id: 1
title: Post title
date: 2017-01-06T00:00:00.000Z
location: Project location
category: Post category
description: Post description
images-array:
 - image: image-1.jpg
   alt: This is some alt text
 - image: image-2.jpg
   alt: This is some alt text
 - image: image-3.jpg
   alt: This is some alt text
---

For Loop:

{% for item in post.images-array %}
  <img class="img-responsive" src="img/portfolio/{{ item.image }}" alt="{{ item.alt }}">
{% endfor %}

使用Bootstrap列进行循环:

{% for post in site.posts %}
    <div class="portfolio-modal modal fade" id="portfolioModal-{{ post.modal-id }}" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">

            <div class="modal-content">
                <div class="close-modal" data-dismiss="modal">
                    <div class="lr">
                        <div class="rl"></div>
                    </div>
                </div>

                <div class="modal-body">

                    <h2>{{ post.title }}</h2>

                    <p class="item-intro text-muted"> {{ post.subheading }} </p>

                    <p>{{ post.description }}</p>

                    {% for item in post.images-array %}
                    <div class="col-sm-4">
                        <img class="img-responsive" src="img/portfolio/{{ item.image }}" alt="{{ item.alt }}">
                    </div>
                    {% endfor %}

                    <ul class="list-inline">
                        <li>Date: July 2014</li>
                        <li>Location: {{ post.location }} </li>
                        <li>Category: {{ post.category }} </li>
                    </ul>

                    <button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-times"></i> Close Project</button>
                </div>

            </div>
        </div>
    </div>
{% endfor %}