# Variable in include param

**URL:** <https://talk.jekyllrb.com/t/variable-in-include-param/7614>\
**Category:** Uncategorized\
**Created:** [August 30, 2022, 12:45am UTC](https://talk.jekyllrb.com/t/variable-in-include-param/7614 "2022-08-30T00:45:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aconstlink](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/aconstlink/32/4849_2.png) [@aconstlink](https://talk.jekyllrb.com/u/aconstlink)\
**Post date:** [August 30, 2022, 12:45am UTC](https://talk.jekyllrb.com/t/variable-in-include-param/7614/1 "2022-08-30T00:45:22Z")

</div>

Hi there.

I am using the alembic theme and there is a `figure` include and is used like this:  
`{% include figure.html image="/test.png" width="100%" %}`

Now, I would like to add a front matter variable `preview_image` to a post that should be used in the excerpt of that post in the blog page in order to show an image in the excerpt.  
So I edited the particular include `post_list.html` so it contains:

```auto
{% if page.preview_image %}
  {% include figure.html image="{{ page.preview_image }}" width="100%" %}
{% endif %}

```

Including this code results in an error message:

`Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: figure.html image="/test.png" Valid syntax: {% include file.ext param='value' param2='value' %} in D:/Ruby/Ruby31-x64/lib/ruby/gems/3.1.0/gems/alembic-jekyll-theme-4.1.0/_layouts/blog.html`

But if I hard code the image file name in the `post_list.html` addition like so:

```auto
{% if page.preview_image %}
  {% include figure.html image="/test.png" width="100%" %}
{% endif %}

```

it just works. But as you can see in the error message, the file name is resolved just right.

Not sure what to do. I tried to `capture` the variable before using it in the `image` parameter, but also didn’t work. Maybe there is some sort of resolution problem? Can someone help me out here?

```auto
>jekyll --version
jekyll 4.2.2

```

---

<div class="post-metadata">

**Author:** ![jhvanderschee](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/jhvanderschee/32/583_2.png) [@jhvanderschee](https://talk.jekyllrb.com/u/jhvanderschee)\
**Post date:** [August 30, 2022, 6:02am UTC](https://talk.jekyllrb.com/t/variable-in-include-param/7614/2 "2022-08-30T06:02:39Z")

</div>

Don’t use brackets inside an if. You should do something like this:

{% if page.preview\_image %}  
{% include figure.html image=page.preview\_image width=“100%” %}  
{% endif %}

---

<div class="post-metadata">

**Author:** ![aconstlink](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/aconstlink/32/4849_2.png) [@aconstlink](https://talk.jekyllrb.com/u/aconstlink)\
**Post date:** [August 30, 2022, 11:47am UTC](https://talk.jekyllrb.com/t/variable-in-include-param/7614/3 "2022-08-30T11:47:30Z")

</div>

That does the trick. I thought I tried every possible variation there…

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [August 31, 2022, 4:44pm UTC](https://talk.jekyllrb.com/t/variable-in-include-param/7614/4 "2022-08-31T16:44:48Z")

</div>

Adding a small correction to the answer above, the curly bracket is only supported for interpolating the include’s file name. The parameters shouldn’t have curly brackets irrespective of being enclosed by `if` blocks.
