0
votes

When i use

{% include folder1/folder1_1/img.jpg %}

it works perfectly, But when i try to generate the filename dynamically let's say :

{%capture filename %} {{'folder1/folder1_1/'}}{{ images[0] }}{{ '.jpg' }}{% endcapture %}

{% include {{ filename }}  %} 

with images[0] = 'img' for example, i get the error that says :

Liquid Exception: Invalid syntax for include tag. File contains 
invalid characters or sequences ...

I Don't understand why including file by providing the complete path(static path) works whereas generating the filename dynamically won't work !

Any help would be more than appreciated.

2

2 Answers

1
votes

After more research on the internet it seems that dynamic filename paths can't be added due to the fact that the included files are calculated and added at the compilation phase and not at run time phase.

And compilation phase means dynamic paths aren't yet recognized.

0
votes

Maybe more luck with :

{% capture filename %}folder1/folder1_1/'{{ images[0] }}.jpg'{% endcapture %}
{% include {{ filename }}  %}