How to include all files in a folder in Jekyll?

左心房为你撑大大i 提交于 2020-01-05 09:35:24

问题


In Jekyll you can include a file by doing:

{% include some-folder/some-file.html %}

If you add more files to the folder you have to manually add them:

{% include some-folder/some-file-2.html %}
{% include some-folder/some-file-3.html %}
{% include some-folder/some-file-4.html %}

Is there a way in Jekyll to include all files in a folder automatically?


回答1:


It seems possible to have a variable name in an include (source).

If this is allowed:

{% include {{ page.my_variable }} %}

Then also this is allowed:

{% include include_all_files.html folder="some-folder" %}

With an include_all_files.html that looks like this:

{% for file in site.static_files %}
  {% if file.path contains include.folder %}
    {% include {{ file.path }} %}
  {% endif %}
{% endif %}


来源:https://stackoverflow.com/questions/53035330/how-to-include-all-files-in-a-folder-in-jekyll

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