【问题标题】:How can I place multiple images in a modal on my Jekyll site?如何在我的 Jekyll 网站上以模态形式放置多个图像?
【发布时间】:2017-01-11 19:26:53
【问题描述】:

我正在使用修改后的 Bootstrap 主题 (specifically this theme) 和 Jekyll 构建一个网站。这是我第一次使用 Jekyll,到目前为止一切都很顺利,直到这让我很困惑。

就像我上面链接的引导主题一样,我有一个投资组合部分,它打开了一个模式,我想在其中包含几张照片和一段文字。到目前为止,我已经让模态帖子的其他元素按照我想要的方式工作,但无法找到添加多个图像的方法。

这是我的投资组合模式的 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
---

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

【问题讨论】:

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


    【解决方案1】:

    构建图像和 alt 标签的序列/数组/列表以替换 Front Matter 中的 img: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循环:

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

    使用引导列的 For 循环:

    {% 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 %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      相关资源
      最近更新 更多