How to use a {% exiftag tagname,[source],[file] %} Liquid tag representing a date and output it using date: "%b %-d, %Y"

I am reading the DateCreated EXIF field using GitHub - remvee/exifr: EXIF Reader (Liquid tag defined here: jekyll-exiftag/jekyll-exiftag.rb at master · benib/jekyll-exiftag · GitHub) as follows:

{% exiftag date_time, , {{ image.path }} %}

However, this outputs as such:

2021-01-09 00:00:00 +0100

I have seen some other examples (not related to EXIF) and whenever you have the format above, you can tweak it as such:

{{ site.time | date: "%b %-d, %Y" }}

This will output the following desired result:

Jan 09, 2021

However, I am a bit confused: how can I make use of {% exiftag date_time, , {{ image.path }} %} yet format it in the desired way ("%b %-d, %Y")?

I am trying the following, but it does not work:

{{% exiftag date_time, , {{ image.path }} % | date: "%b %-d, %Y" }}

P.S.: Perhaps it is easier to just include the date inside the filename, and get the date from the filename, although I also don’t know how to do that.

1 Like

You can try using the capture tag:

{% capture image_datetime %}
{% exiftag date_time, , image.path %}
{% endcapture %}

That will capture (hence the name :stuck_out_tongue:) the output of exiftag and will be assigned to the variable image_datetime, then you could use it with the date filter, if image_datetime is a date/time object.

{{ image_datetime | date: "%b %-d, %Y" }}
2 Likes

Indeed, was going to recommend capture. You can chain filters in {{ }} but because you have a tag in {% %} you can’t send that to a filter. So then you capture the content of tag output as a variable and then use that as with a filter.

To keep your code light, you can make an includes file.

_includes/image-date.html

{% capture image_datetime %}
{% exiftag date_time, , include.path %}
{% endcapture %}
{{ image_datetime | date: "%b %-d, %Y" }}

You can add a span with a class if you want.

Then you can use that all over.

Image date is {{ include image-date.html path=image.path }}
1 Like