Invalid syntax for include tag | Variable inside include {% %}

  • [x ] I have a question about using Jekyll.
  • [x ] I updated to the latest Jekyll v3.5.0

  • [x ] I am on (or have tested on) macOS 10+

  • [x ] I was trying to build.

My Errror Message

Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: image_caption.html imageurl=“http://blog.local/images/home/image.jpg” Valid syntax: {% include file.ext param=‘value’ param2=‘value’ %} in index.html


My Reproduction Steps

  • Use a variable inside an include tag, my example is:
    {% include image_caption.html imageurl="{{ site.url }}/images/home/image.jpg" title="some title text" caption="some caption text" %}

So I guess there’s some escaping to be done in this: {% imageurl="{{ site.url }} %} or is that not something achievable?
I’m not into Ruby, so getting stuck here. Any advice appreciated.

the problem is you cannot use curly brackets inside the include - it breaks it. So if you want to do that you have to assign the variable outside of the include:

2 Likes

hey @rdyar, spot on! Your answer was great. I have been able to use the capture function.
Thank you so much!

A question:
I see that I cannot indent the caption on a newline, for example:

{% capture img_url %}
//some stuff here
{% endcapture %}

This produces some random weird characters. So it has to been all on same line:

{% capture img_url %}//some stuff here{% endcapture %}

Why is that? (for my personal knowledge)

That doesn’t sound correct to me, I have seen multi line capture statements before I think. Maybe it is your content.

That said I can’t think of anywhere I use capture so I don’t know for sure.

I have tried a couple of times, same behaviour, even with texts…
I’m using Jekyllrb 3.5.0

if you give a full example maybe someone will try it to see if they can verify it?

It’s not a priority for me, I will get back to this post later for the sake of debugging the behaviour… cheers

And thank you again for all your amazing help @rdyar, you are awesome!