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.