问题描述
是否可以在YAML Front Matter变量中使用Liquid标签?
Is it possible to use Liquid tags in YAML Front Matter variables?
例如,如果test.html包含:
For example if test.html contains:
---
variable: "Date: {% date: '%D' %}"
---
{{ page.variable }}
然后Jekyll将生成以下HTML:
then Jekyll will generate the following HTML:
Date: {% date: '%D' %}
而不是类似的东西:
Date: 03/13/14
基本上,我希望处理YAML Front Matter变量中的Liquid标签.
Basically I'd like the Liquid tags in the YAML Front Matter variables to be processed.
推荐答案
听起来您正在尝试将格式化的日期存储在变量中,因此您不必每次使用时都重新格式化日期.
It sounds like you're trying to store a formatted date in a variable so you don't need to re-format the date each time you use it.
除了在前件上过滤日期外,您还可以在前件下添加一个Liquid捕获语句.这将允许您将格式化日期分配给变量,以便可以在表达式中使用它.
Rather than filtering the date in the front matter you could just add a Liquid capture statement just below the front matter. This will allow you assign your formatted date to a variable so you can use it in expressions.
---
title: Some sweet title
layout: default
date: 2014-9-17 # Could come from post's filename, but I put it here explicitly
---
{% capture formatted_date %}{{ page.date | date: "%-d %B %Y" }}{% endcapture %}
一旦有了新的格式化日期变量,就可以在任何地方将其用作表达式:
Once you have your new formatted date variable you can use it as an expression anywhere:
{{ formatted_date }}
输出:17 September 2014
这篇关于在YAML Front Matter变量中使用液体标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!