Must include files in nanoc always be in the layouts folder?

自古美人都是妖i 提交于 2019-12-24 04:16:07

问题


We would like to use server side includes (SSI) in the content of our nanoc site. This would allow us to chunk shared information and include it in multiple pages. It would also allow us to only maintain one source file of this shared information.

I figured out how to add an SSI (partial) in nanoc. As you know in nanoc we have the following root level folders, among others:
/content/
/layouts/

According to the instructions I found (https://nanoc.ws/doc/items-and-layouts/#partials), it seems the “partials” or include files need to be in the /layouts/ folder (outside of the /content/ folder).

For example: The following code is used to insert the include file /layouts/partials/shared/test.html

<%= render 'partials/shared/test/' %>

In other words, the code assumes the include file will be placed in the layouts folder. Do you know of a way to change the default path for SSIs to /content/? This way we won’t mix content with layouts?

Thank you in advance.


回答1:


Partials by default are in the layouts/ directory, and are used through the rendering helper using the #render helper method.

However, you can also put content to include (“partials”) in the content/ directory, too, although the approach then is different.

For example, create content/partials/foo.txt:

I am included!

Make sure the partial files are not routed nor compiled, so edit Rules and ensure these rules are executed first:

compile '/partials/*' do
  write nil
end

Now in any item or layout you can include this partial:

<%= @items['/partials/foo.*'].compiled_content %>

This assumes the includer item/layout is filtered using ERB, but you could also use Haml or so.

You can let the compile rule do some processing, e.g. perform Markdown filtering, and then the HTML output from the filter will be included.



来源:https://stackoverflow.com/questions/20367811/must-include-files-in-nanoc-always-be-in-the-layouts-folder

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