Search code examples
gruntjshandlebars.jsassemble

Nested Partials in Assemble


Revisiting Assemble after a few months away from it. I'm building out my Gruntfile.js with the Assemble options.

Setup

Gruntfile.js

assemble: {
  options: {
    flatten: true,
    production: false, // set to true before delivery
    assets: 'assets',
    postprocess: require('pretty'),

    // Metadata
    pkg: '<%= pkg %>',
    site: '<%= site %>',

    // Templates
    partials: '<%= site.includes %>',
    layoutdir: '<%= site.layouts %>',
    layout: '<%= site.layout %>',
  },
  site: {
    files: {'<%= site.dest %>/': ['<%= site.templates %>/pages/*.hbs']}
  }
}

_config.yml

# Assemble Templates
templates:        <%= site.src %>/templates
includes:         <%= site.src %>/templates/includes/**/*.hbs  
layouts:          <%= site.src %>/templates/layouts
layout:           default.hbs

Question(s)

Within my .hbs files for the layouts, how would I go about referencing nested partials, ie temples/includes/global/head.hbs

This is how you'd call it if was at the root level:

<head>
  {{> head }}
</head>

What's the markup for a nested partial? Check the docs and it didnt come to me as an answer there; sorry.


Solution

  • You access the partial the same way {{> head }}. We're only using the basename of the file to name the partial. There's no built in way to modify that in assemble 0.4.x.

    If you have different partials with the same filename in different folders, then the last one wins.