无法分配在Jekyll模板中工作的位置

时间:2015-06-03 17:46:58

标签: yaml jekyll

我在Jekyll建立了我的网站。

数据文件在其他地方解析时工作正常,但是当我尝试使用where子句访问特定记录时,我没有得到任何结果。

查看https://github.com/ohiweb/ohiweb.github.io

上的项目

麻烦的页面位于portfolio \ betimca \ index.html

portfolio.yml

projects:
  - name: "betimca"
    title: "Betimca Subdivision Project"
    description: "These beautiful houses in Betimca feature classical elements with modern conveniences. Brick facades are crafted with accents tht stand out for maximum curb appeal. Gables with generous windows allow maximum light to upstairs rooms and add to their distinguished character."
    feature: "betimca_1a.jpg"
    media: "portfolio/betimca"
    images: [betimca_1a.jpg,betimca_1b.jpg,betimca_1c.jpg,betimca_2a.jpg,betimca_2b.jpg,betimca_3a.jpg,betimca_3b.jpg]
    tags: ["portfolio", "new construction", "residential", "subdivision"]

的index.html

{% assign project = site.data.portfolio.projects | where: "name", "betimca" %}
<section>
    <div class="row">
        <div class="col col-md-4">
            <header class="page-header">
                <h1>
                {{project.title}}
                </h1>
            </header>
            <p>{{project.description}}</p>
        </div>
        <div class="col col-md-6 col-md-offset-2">
            <img src="/media/{{project.media}}/{{project.feature}}" class="img-responsive img-thumbnail">
        </div>
    </div>
    <hr>
    <div class="row">
      {% for image in project.images %}
      <div class="col col-xs-6 col-sm-4 col-lg-3">
        <span class="thumbnail">
          <img src="/media/{{project.media}}/{{image}}" alt="{{project.title}} {{image}}">
        </span>
      </div>
      {% endfor %}
    </div>
</section>

1 个答案:

答案 0 :(得分:3)

{% assign project = site.data.portfolio.projects | where: "name", "betimca" %}

这将返回一个包含一个元素的数组。

如果你想获得项目中的元素,你可以这样做:

{% assign project = site.data.portfolio.projects | where: "name", "betimca" | first %}

现在你的页面正常工作。