Invalid syntax for include tag (using a variable)

I have a collection where each item contains a variable that defines a partial to include called ‘feature_include’.

Based on what the docs say, I tried adding this to my template:

{% include {{page.feature_include}} %}

…but keep getting 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/home.html

I’ve tried lots of variations based on the several GH issues and SO posts I found (e.g., no curly braces, temp variable assignment, etc.), but nothing works. The partials are there, and work fine if I paste in a literal value (e.g., ‘example_feature.html’).

Am I missing something?

I just tested it and it worked for me. I’m guessing your naming is off. Here is what worked for me.

  1. Created _includes/example_feature.html and put some test content in it.
  2. Edited a layout, _layouts/post.html and added {% include {{page.feature_include}} %}
  3. In a post added feature_include: example_feature.html to its YAML Front Matter.
  4. Built the site. Test content in the include appears in the post.

I think I once noticed liquid did not like numbers in things, I think I got an error like the one you show.

Hmm. Tried a completely fresh rvm, ruby 2.3.3p222, and jekyll 3.4.3, created a new project, grabbed the default minima post template, followed your steps, same error.

Sorry to bring up an old issue - did you fix this?

I was having similar issues, but only when my include was nested inside an if that referenced another variable.

Using your example, I could produce the error with:

other_variable: true in YAML Front Matter, and

{% if page.other_variable %}
  {% include {{page.feature_include}} %}
{% endif %}

But if the the if is removed, or changed to the following:

{% if page.feature_include %}
  {% include {{page.feature_include}} %}
{% endif %}

to reference the same variable, it works fine.

@peroh Thanks. I had the same issue and this helped. Seems like a bug. I’m on v3.8.5.