Include
Include shortcode can include files of different types. By specifying a language, the included file will have syntax highlighting.
|
|
Attributes:
Name | Description | Default |
---|---|---|
file | path to the included file relative to the Hugo root | undefined |
language | language for syntax highlighting | undefined |
type | special include type (html,page ) |
undefined (rendered as markdown) |
options | highlighting options | linenos=table |
Examples
Markdown file (default)
If no other options are specified, files will be rendered as Markdown using the RenderString
function.
Location of markdown files
If you include markdown files that should not get a menu entry, place them outside the content folder or exclude them otherwise.
|
|
Example Mardown include
File including a simple Markdown table.
Head 1 | Head 2 | Head 3 |
---|---|---|
1 | 2 | 3 |
Language files
This method can be used to include source code files and keep them automatically up to date.
Result:
|
|
Special include types
HTML
HTML content will be filtered by the safeHTML
filter and added to the rendered page output.
|
|
Example HTML include
This is heading 4
This is heading 5
This is heading 6
Pages
In some situations, it can be helpful to include Markdown files that also contain shortcodes. While the default method works fine to render plain Markdown, shortcodes are not parsed. The only way to get this to work is to use Hugo pages. There are several ways to structure these include pages, so whatever you do, keep in mind that Hugo needs to be able to render and serve these files as regular pages! How it works:
- First you need to create a directory within your content directory. For this example site
_includes
is used. - To prevent the theme from embedding the page in the navigation, create a file
_includes/_index.md
and addGeekdocHidden: true
to the front matter. - Place your Markdown files within the
_includes
folder e.g./_includes/include-page.md
. Make sure to name it*.md
. - Include the page using
{{< include file="/_includes/include-page.md" type="page" >}}
.
Resulting structure should look like this:
|
|
alipay
Author Houmin Wei
Publish January 20, 2023
LastMod July 11, 2023 (8d68658)
License 本作品采用 CC BY-NC-ND 4.0 许可协议进行许可,转载时请注明原文链接
如果你在浏览博客的过程中发现了任何问题,欢迎在对应文章下评论。如果你有其他事情想要咨询,可以通过邮件联系我。
-
No backlinks found.