89736

Using liquid tags in YAML Front Matter variables

Question:

Is it possible to use Liquid tags in YAML Front Matter variables?

For example if test.html contains:

--- variable: "Date: {% date: '%D' %}" --- {{ page.variable }}

then Jekyll will generate the following HTML:

Date: {% date: '%D' %}

instead of something like:

Date: 03/13/14

Basically I'd like the Liquid tags in the YAML Front Matter variables to be processed.

Answer1:

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.

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 }} outputs: 17 September 2014

<a href="https://stackoverflow.com/questions/7395520/how-does-jekyll-date-formatting-work" rel="nofollow">More on formatting the date itself.</a>

Recommend

  • How to solve CORS problem of my Django API?
  • Why no memory leak?
  • Django: copy data from one database to another
  • ObjectDisposedException on a ASP.NET Core 2.0 MVC custom database initializer class
  • Why do we have to put an asterisk on method parameter types in Objective-C?
  • JSON printing all paths from root to leaf
  • Rezize HTML Canvas size after transformed operation
  • Why context.Wait in StartAsync didn't stop the dialog
  • Reuse jQuery object from an iframe?
  • Is js executed after form synchronized submit
  • How to set title name of the pdf. While viewing the Document(New Tab)
  • How to Export CSV file from ASP.NET core
  • Delete get variables and .php using htaccess
  • Accessing parent namespace inside a Shiny Module
  • Salesforce API: How to identify a Case from an email reference code (“[Ref: … :Ref]”)?
  • yii rewrite url with many sub categories
  • git clone, upload-pack out of memory
  • playing mp3 from nsbundle
  • python selenium scraping tbody
  • Set SelectedIndex of ListView in FlipView_SelectionChanged event
  • How to redirect into different page by user type in php and mysql
  • ASP.NET MVC razor view, post to a different model from the original model binding?
  • How do I use libcurl to printf a remote FTP directory listing?
  • How can i move Clearcase dyamic/snapshot views to another host (Linux)
  • Content-Type alternative in MQTT
  • JQuery: Infinite input select
  • How to turn off notice reporting in xampp?
  • how to run ejabberd with Erlang on Heroku?
  • matrix multiplication apache pig
  • Google App Engine backend servlet not responding
  • Make checkout phone field optional for specific countries in WooCommerce
  • Excel VBA : conditional formatting of sheet1 cells from sheet2 values in excel 2007
  • Grails - How to implement a foreign key relationship not using an id column?
  • Call Microservice from another Microservice within Docker
  • Creating random wired topology for given arbitrary number of nodes on NS2
  • convert json to excel in java