【发布时间】:2019-09-08 12:29:15
【问题描述】:
如果我指定{% assign member = site.data.members[page.author] %} 并在页面的frontmatter 中插入author: valuehere,数据可以显示。如果我指定{% for member in site.data.members %} ~~~ {{ member.name }} ~~~ {% endfor %},它将不会循环
== members.yml
attorney1:
birth_country: "United States of America"
birth_city: "Paso Robles"
birth_region: CA
birth_zip: 93446
birth_date: "05/1968"
education: "Southeastern University: B.A. History – 2008, University of Florida Levin College of Law: Juris Doctor – 2001"
image: attorney1.jpg
nationality: "United States of America"
name: "Attorney One Esq"
first_name: "Attorney"
last_name: "One"
honorary: Esquire
email: email@example.com
home_country: "United States of America"
home_city: "Ocala"
home_region: "FL"
home_zip: "34482"
gender: Male
permalink: "/lawyers/attorney1.html"
ext: "02"
practices: "Personal Injury · Insurance Litigation"
web: "Lawyer One Esq is a past member of the Hillsborough County Bar Association and Young Lawyers Division, the Lakeland Bar Association, and Emerge. Jon was also served on the Board of Directors for Tri-County Human services, which serves Polk, Hardee, and Highlands counties. Lawyer One Esq is currently a member of the Jacksonville Bar Association."
我尝试过像这样重新格式化数据文件:
- author: attorney1
name: "Attorney One"
~~~
然后像这样重新编码作者页面:
---
layout: attorney
title: "Attorney One"
crumbtitle: "Attorney One"
permalink: "/lawyers/attorney1.html"
jsontype: lawyer
genre: Law
headline: "Affordable Marion County Legal Representation"
author: attorney1
---
{% assign author = site.data.members | where: "author", "{{page.author}}" %}
<!-- Main -->
<article id="main">
<header class="special container">
<span class="icon fas fa-user-circle"></span>
<h2>About {{ author.name }}</h2>
{{ author.web | markdownify }}
</header>
<!-- One -->
目标是能够使用 for 循环并为作者页面提取数据。如果我像这样格式化数据文件:
attorney1:
name: "Attorney one"
作者页面使用{% assign author = site.data.members[page.author] %} 并打破了for循环。
【问题讨论】:
-
你在乎钥匙吗? (本例中为
"attorney1")因为 for 循环可能会遍历键/值对。你可以试试for member in site.data.members.values看看是否可行? -
@3limin4t0r 此数据文件中还有其他键。刚卡住!它可以调用特定的键。只是不在 for 循环中。
-
@3limin4t0r 如果我将数据文件格式切换为
- author: attorney1并在下面有 2 个空格,则循环有效并且作者页面停止为{% assign member = site.data.members[page.author] %}工作 -
@3limin4t0r
{% assign author = site.data.members | where: "author", "{{page.author}}" %}在作者页面上也不起作用。 -
为我的问题投票?
标签: ruby jekyll liquid jekyll-theme