Page Variable in Include

According to the documentation, I should be able to use a variable set in the front matter of a page in an include statement like so:

{% include {{ page.my_variable }} %}

However, when I attempt to serve my site with this method I get this error:

Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: Valid syntax: {% include file.ext param='value' param2='value' %} in /_layouts/page.html

My variable set in front matter is sidebar: sticker-sidebar.html and my include statement is {% include {{ page.sidebar }} %}

I’ve tried a few things to solve the problem and it does work if the front matter variable includes a -. So sidebar: sticker- and {% include {{ page.sidebar }}sidebar.html %} works just fine. However, if I remove the - from the variable and add it to the include statement, the page breaks.

Is this a bug in Jekyll or some nuance of variables and includes that I can’t figure out?

interesting, not sure.

If your front matter is just stickersidebar.html will it work? sounds like you are saying no. but your first example has a dash.

What version of Jekyll?

I just did the following with Jekyll 3.8.3 and it’s works as expected.

  1. Created _includes/sticker-sidebar.html
  2. Added sidebar: sticker-sidebar.html to a page’s front matter
  3. Added {% include {{ page.sidebar }} %} to the layout.

Site built with no errors and the test content in sticker-sidebar.html showed up. Do you have a public repo we can look at?

Sorry, my mistake there. If it ends in a trailing dash, it works. If the dash is included in the filename, it doesn’t work.