This is my first post. I’m new to Jekyll, Git and blogging in general.
I’m trying to create a markdown file that allows me to modify the permalink by using what’s stored inside another variable from the YAML front matter block, here’s an example:
---
layout: post
title: Title Page
custom_slug: my-custom-slug
permalink: blog/{{ page.custom_slug | :title }}/
---
Jekyll will just display what ever text it contains inside the ‘permalink’ variable. I am unable to call a variable inside of the YAML front matter block.
Liquid is not evaluated in YAML frontmatter. You can try flatify plugin covered in the thread. Or you going to have have to duplicate your text in two values.
If it was some other field and not permalink, I would have said move the logic to a layout which can take a field on the page and rework it into html output
Thanks, but I’ve already found a workaround for my particular problem by simply not having the need to use liquid tags inside of the YAML front matter block. Although, it would be nice to know more about whether this was an intentional design feature or not.
I haven’t tested this, but looking at the entry on permalinks in Jekyll docs, the following should be a way to achieve what you’re trying without using Liquid:
---
title: My title
slug: custom-slug
permalink: /:slug/:title
---
As explained in the docs, if you don’t override the slug variable with custom frontmatter as above, by default slug represents the document title slugified.
If you really want to be able to use Liquid in YAML, there is a good post on Stack Overflow here with a couple of workarounds.
And so avoid an anti pattern, i would recommend you update the filename itself in order change the output URL for a given post, rather than only changing the permalink on the post.
If you don’t like the date in the filename then that’s a different issue and already covered in another Jekyll forum post.
And the date required in the filename and output avoids conflicts between posts on different dates with the same name and also allows your RSS feed and site map and posts list to be sorted by date.
Hi, I am new to jekyll but I quickly ran into the desire to have liquid variable in the front matter and I stumbles on this which worked for the title and other variable. However I would like o flatify the date and it’s giving me an error I am presuming because of the % sign in column 48 of line 4. I am not sure if I need escape the quotes or % sign or how to escape them (I tried to escape with \ and it still gave me an error)
---
layout: post
title: Test
caption: "{{site.images}}{{ page.date | date: "%Y%m%d" }}_"
---
<h1>{{ page.caption | flatify }}</h1>
error:
Error: YAML Exception reading /home/test/Documents/websites/websitename/_posts/2022-05-26-1.md: (<unknown>): found character that cannot start any token while scanning for the next token at line 4 column 48
Some background about what I am trying to accomplish. Instead of naming my post I am just giving them a name like 2022-05-26-1.md and then name them using the title: in the front matter. If I need to attach an image I just put the image in the /assets/img folder with the name of the date 20220526_1.jpg. Then in the text where I need to use the image I just write ![img]({{ page.caption | flatify}}_1.jpg)