How can I dynamically reference template file in volt template?

心不动则不痛 提交于 2019-12-09 20:57:33

问题


We know, {% include header.volt %} is reference file with name's header.volt.

How can I dynamically reference template file in volt template?
like this:
     {% include variable %}
     when variable equal footer.volt, theen the program will reference file with name's footer.volt
    when variable equal index.volt, then the program will reference file with name's index.volt...

thanks!


回答1:


I'm not sure if using variables in include will work, but you can always use partial() to include your template:

{% set partialName = 'footer' %}
{{ partial('partials/'~partialName) }}


来源:https://stackoverflow.com/questions/19827002/how-can-i-dynamically-reference-template-file-in-volt-template

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