我正在尝试从粘性为“ true”的集合中输出一项。
我已经尝试过Getting a specific item from a collection in Jekyll
来自集合_defense/dui.html
---
layout: right-sidebar
title: "Drug Offense"
crumbtitle: "drug-related crime"
permalink: "/practice-law/criminal-law/drug-offense.html"
sticky: true
twitter: "Working on this"
facebook: "Civil Litigation can cost you hundreds if not thousands of dollars if you are not adequately protecting your rights. Civil Litigation can be anything from traffic tickets, hurricane insurance claims to medical malpractice. Call or write for a free, no obligation review of your situation."
web: "An arrest for a drug offense can have significant consequences. Drug offense charges can range from possession to trafficking and can carry significant penalties, including minimum mandatory prison sentences.
The Prosecutor’s process of deciding what if any criminal charges to file can be a very critical stage in the case. This process happens very early in a case and as your lawyers, we can impact this decision.
**DO NOT** make a statement to law enforcement without consulting us first. Call Cagan & Cagan today for a free consultation."
在收藏页_practices/criminal-defense.html
<!-- One -->
{% assign defenses = site.defense | where:"true", "page.sticky" | limit:1 %}
{% assign defense = defense[0] %}
{{ defense | inspect }}
<section class="wrapper style4 container">
<div class="row gtr-150">
<div class="col-8 col-12-narrower">
<!-- Content -->
<div class="content">
<section>
<header>
<a href="#" class="image featured">
<h2>{{ defense.title }}</h2>
</a>
</header>
<p>{{ defense.web | markdownify }}</p>
</section>
</div>
</div>
我现在得到零价值。我要第一项内容为true,并在此处结束。
答案 0 :(得分:1)
where
过滤器语法为:
{% assign res = array | where: "key", "expected value" %}
但是,您已经颠倒了参数order:
{% assign res = hash | where: "expected value", "key" %}
因此,您可以替换
{% assign defenses = site.defense | where:"true", "page.sticky" | limit:1 %}
{% assign defense = defense[0] %}
作者
{% assign defense = site.defense | where: "sticky", "true" | first %}
注释:
first
替换数组limit:1 > array[0]
中的数组的第一个元素。limit
是for
loop control structure parameter。您不能在assign
标签中使用它。编辑:如果要从帖子,页面或收藏集中获取某些项目,则可以根据前题变量进行操作:
{% assign items = site.anycollection | where: "any_key", "string_value" %}
然后,您可以使用for循环并最终使用limit
and offset
parameters打印此结果数组中的任何内容。
{% for item in items limit:2 %}
and so on ....