简体   繁体   English

Jekyll 包括在没有模板的情况下无法在 GitHub 页面中工作

[英]Jekyll includes not working in GitHub Pages without a template

I'm trying to publish my own website on GitHub Pages.我正在尝试在 GitHub 页面上发布我自己的网站。 I want to include some repeating parts of code (header) in many files so that I don't always have to copy-paste them.我想在许多文件中包含一些重复的代码部分(标题),这样我就不必总是复制粘贴它们。 I wanted to use the include functionality offered by Jekyll:我想使用 Jekyll 提供的包含功能:

{% include example.html %}

I've put the file I want to include in the _includes directory, however, for some reason it seems to work only if I use a layout in the main file.我已将要包含的文件放在 _includes 目录中,但是,出于某种原因,它似乎只有在主文件中使用布局时才有效。 Am I doing something wrong?难道我做错了什么? If not, is it possible to use Jekyll includes without a layout?如果没有,是否可以在没有布局的情况下使用 Jekyll include? (Because I have set all my html files to work without it) (因为我已将所有 html 文件设置为在没有它的情况下工作)

My best guess is you are also removing the yaml tags when you remove the layout.我最好的猜测是,当您删除布局时,您也会删除 yaml 标签。 Try this in your index.html file在你的 index.html 文件中试试这个

---
---
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>First try</title>
  </head>
  <body>
    {% include first-try.html %}
  </body>
</html>

You need those --- tags to process Liquid in the file.您需要那些---标签来处理文件中的 Liquid。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM