Search code examples
layoutjekyllyaml-front-matter

Using post header variables in custom layout in Jekyll


I've to define a post like as shown which is derived from mylayout.html:

---
layout: mylayout
title:   "My Post"
varA: default
---
This post is bla bla bla ...

How can i have a layout that makes use of varA in mylayout.html?. I wish to achieve mylayout.html as something like following:

---
layout:default
---
<H1>This is {{post.varA}}</H1>

{{content}}

Solution

  • Found a solution, I was using {{post.varA}} in layout considering it's a post variable. But, I guess inside layout it is accessed as {{page.editorfile}}. Using following mylayout.html solved this issue:

    ---
    layout:default
    ---
    <H1>This is {{page.varA}}</H1>
    
    {{content}}