concept partial in category hapi

appears as: partials, partial
hapi.js in Action

This is an excerpt from Manning's book hapi.js in Action.

Partials are smaller, self-contained blocks. They may be used for repeating elements in a list, or for blocks that appear on many different views, such as ads or widgets.

I can refactor the home page view created in the previous section to make use of layouts and partials. Figure 3.11 shows how the home page view can be deconstructed into a single layout and multiple partials.

Figure 3.11. Deconstructing the home page into a layout, view, and partials

The index view now contains only the repeating recipe summary partial. To output a partial, the expression used is {{> partialName}}. The stripped down index.hbs view is shown here.

Listing 3.16. views/index.hbs
{{#each recipes}} {{> summary}} {{/each}}

Layouts and partials are invaluable elements in building DRY views. They help keep your templates small and focused and they increase reusability and improve the maintainability of your web applications.