Does nanoc support nested partials?

302 Views Asked by At

I am using partials in nanoc, and I was wondering if it's possible to nest partials in nanoc. In other words, can I have a partial within a partial?

When I tested this, the site compiled, but the nested partial did not display.

I'm using the Partials implementation described in this stackoverflow post: Must include files in nanoc always be in the layouts folder?

While nested partials are not required for what we're trying to do, I was just wondering if this is possible.

Thank you in advance.

1

There are 1 best solutions below

1
On

Yes, you can use nested partials with nanoc. Here's a way to demonstrate this:

  1. Create a new site using nanoc.

  2. From within the site directory, create the folder content/partials.

  3. 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.

  4. 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 %>
    
  5. 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
    
  6. 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:

    A Brand New nanoc Site

    This is the outer partial.

    This is the inner partial.