我在 nanoc 中使用部分,我想知道是否可以在 nanoc 中嵌套部分。换句话说,我可以在一个部分中有一个部分吗?
当我对此进行测试时,该站点已编译,但嵌套的部分未显示。
我正在使用此 stackoverflow 帖子中描述的 Partials 实现:必须在 nanoc 中包含文件始终位于布局文件夹中?
虽然我们尝试做的事情不需要嵌套部分,但我只是想知道这是否可能。
先感谢您。
我在 nanoc 中使用部分,我想知道是否可以在 nanoc 中嵌套部分。换句话说,我可以在一个部分中有一个部分吗?
当我对此进行测试时,该站点已编译,但嵌套的部分未显示。
我正在使用此 stackoverflow 帖子中描述的 Partials 实现:必须在 nanoc 中包含文件始终位于布局文件夹中?
虽然我们尝试做的事情不需要嵌套部分,但我只是想知道这是否可能。
先感谢您。
Yes, you can use nested partials with nanoc. Here's a way to demonstrate this:
Create a new site using nanoc.
From within the site directory, create the folder content/partials
.
Create the "outer" and "inner" partial content. In the file content/partials/_outer.html
, place:
<p>This is the outer partial.</p>
<p><%= @items['/partials/_inner/'].compiled_content %></p>
And in the file content/partials/_inner.html
:
This is the inner partial.
Note that we now have one partial including the contents of another.
Edit the main page, content/index.html
, so it embeds the outer partial:
<h1>A Brand New nanoc Site</h1>
<%= @items['/partials/_outer/'].compiled_content %>
Add these rules to Rules
above the ones already present:
# Filter but do not lay-out partial content
compile '/partials/*' do
filter :erb
end
# Do not output partials; they are only ever embedded in other content
route '/partials/*' do
nil
end
Now generate the site with nanoc compile
. When you view it you'll see the inner partial content nested inside the outer partial content, nested inside the main page, like this:
This is the outer partial.
This is the inner partial.