# Invalid syntax for include tag (using a variable)

**URL:** <https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574>\
**Category:** Help\
**Created:** [May 25, 2017, 2:10pm UTC](https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574 "2017-05-25T14:10:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![foo](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/foo/32/215_2.png) [@foo](https://talk.jekyllrb.com/u/foo)\
**Post date:** [May 25, 2017, 2:10pm UTC](https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574/1 "2017-05-25T14:10:47Z")

</div>

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](http://jekyllrb.com/docs/includes/#using-variables-names-for-the-include-file), 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?

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [May 25, 2017, 8:34pm UTC](https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574/2 "2017-05-25T20:34:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [May 25, 2017, 9:30pm UTC](https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574/3 "2017-05-25T21:30:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![foo](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/foo/32/215_2.png) [@foo](https://talk.jekyllrb.com/u/foo)\
**Post date:** [May 25, 2017, 9:31pm UTC](https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574/4 "2017-05-25T21:31:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peroh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/peroh/32/871_2.png) [@peroh](https://talk.jekyllrb.com/u/peroh)\
**Post date:** [March 10, 2018, 12:47am UTC](https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574/5 "2018-03-10T00:47:23Z")

</div>

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

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

```

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

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

```

to reference the same variable, it works fine.

---

<div class="post-metadata">

**Author:** ![deepfriedbrain](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/deepfriedbrain/32/360_2.png) [@deepfriedbrain](https://talk.jekyllrb.com/u/deepfriedbrain)\
**Post date:** [September 4, 2021, 3:59pm UTC](https://talk.jekyllrb.com/t/invalid-syntax-for-include-tag-using-a-variable/574/6 "2021-09-04T15:59:41Z")

</div>

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