问题
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.
回答1:
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.
回答2:
Maybe more luck with :
{% capture filename %}folder1/folder1_1/'{{ images[0] }}.jpg'{% endcapture %}
{% include {{ filename }} %}
来源:https://stackoverflow.com/questions/36096087/liquid-dynamic-filename-is-not-accepted