问题描述
我在组合液体标签和液体过滤器/管道时遇到麻烦.
I'm having trouble combining a Liquid Tag and a Liquid filter/pipe.
尽管我认为这是一个通用问题,并且与特定插件无关,但是如果相关,我将使用 jekyll-exiftag .
Though I think this is a generic question and not related to the specific plugin, but in case it is relevant, I am using jekyll-exiftag.
标签为:{% exiftag date_time_digitized,{{image_dir}},{{image_name}} %}
.该命令为我提供了拍摄给定照片的日期时间.而且有效.所以下面的代码:
The tag is: {% exiftag date_time_digitized,{{image_dir}},{{image_name}} %}
. This command gives me the datetime that the given photo was taken. And it works. So the following code:
<p>{% exiftag date_time_digitized,{{image_dir}},{{image_name}} %}</p>
正确生成以下输出: 2017-03-04 12:09:23 +0100
我正在尝试使用Liquid date过滤器格式化日期.
I am trying to use the Liquid date filter to format the date.
要测试,以下代码:
<p>{{ '2013-11-29 00:00:00 -0500' | date: '%B %d, %Y' }}</p>
正确生成以下输出: 2013年11月29日
但是,我无法将输出的日期时间通过管道传递到日期过滤器中.
However, I'm not able to pipe the outputted datetime into the date filter.
我尝试了两种方法:
方法1:
<p>{% exiftag date_time_digitized,{{image_dir}},{{image_name}} | date: '%B %d, %Y' %}</p>
方法2:
{% assign image_date = exiftag date_time_digitized,{{image_dir}},{{image_name}} %}
<p>{{ image_date | date: '%B %d, %Y' }}</p>
即使没有过滤器,以下内容也没有输出.
Even the following, without the filter, has no output.
{% assign image_date = exiftag date_time_digitized,{{image_dir}},{{image_name}} %}
<p>{{ image_date }}</p>
我觉得这是一个Liquid语法问题,但是我自己搞不清楚.如果您对此问题有任何见解,我将不胜感激!
I feel like this is a Liquid syntax issue, but I am having trouble figuring it out on my own. I would appreciate any insight into this problem!
推荐答案
我能够使用捕获来做到这一点:
I was able to use capture to do this:
{% capture image_date %}
{% exiftag date_time,{{image_dir}},{{image_name}} %}
{% endcapture %}
<p>{{ image_date | date: '%-m/%-d/%y' }}</p>
这篇关于使用带有液体标签的液体过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!