Liquid dynamic filename is not accepted

拜拜、爱过 提交于 2020-03-06 03:13:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!