Jekyll: Include a file from directory outside of _includes

后端 未结 7 1504
陌清茗
陌清茗 2021-02-07 03:34

I have an directory called /patterns in my Jekyll site, whose structure generally looks generally like this:

_includes _layouts _site /patterns index

7条回答
  •  隐瞒了意图╮
    2021-02-07 04:00

    You can choose to include file fragments relative to the current file by using the include_relative tag for your /patterns/file.html

    For the directory structure you have:

    _includes
    _layouts
    _site
    /patterns/file.html
    index.html
    

    In this case the following doesn't work:

    {% include /patterns/file.html %}
    

    Use include_relative as /pattern is relatif to index.html as the current file:

    {% include_relative patterns/file.html %}
    

    Note:

    You can't use the include_relative tag with any files inside your layouts folder. You can only use include_relative on a page or post. Layouts code is executed in the context of page/post rendering and the include_relative is calculated relative to this page or post, not from the layout itself.

    In this case your code on index.html shall be:

    ---
    layout: null
    ---
    (put all code from _layouts/default.html)
    {% include_relative patterns/file.html %}
    

提交回复
热议问题