Core concept · 04
Partials & @input.
Use partials to express reusable structure once. Nift parses each input as Nift source, so partials can compose other partials and automatically become part of the dependency graph.
A typical partials directory
templates/
template.html
partials/
head.html
header.html
navigation.html
footer.html
analytics.html
Build a page shell from reusable pieces
<!doctype html>
<html lang="en">
@input('templates/partials/head.html')
<body>
@input('templates/partials/header.html')
<main>@content</main>
@input('templates/partials/footer.html')
</body>
</html>
Partials can compose partials
<header class="site-header">
<a href="@pathto('/')">Nift</a>
@input('templates/partials/navigation.html')
</header>
The navigation file is now indirectly used by every page that uses the header. If it changes, Nift's dependency information can identify the affected tracked outputs.
Use partials for repeated page furniture
<!-- templates/partials/docs-sidebar.html -->
<aside>
<a href="@pathto('docs/getting-started')">Getting started</a>
<a href="@pathto('docs/templating')">Template language</a>
<a href="@pathto('docs/commands')">Commands</a>
</aside>
They are not limited to large fragments
A partial can be a whole header, a tiny repeated SVG/logo fragment, a legal notice, a script tag shared by a subset of pages, or a nested navigation section. Extract a partial when reuse makes the project clearer—not merely to maximise the number of files.
Input lookup
@input accepts one path. Nift checks the supplied path and can also resolve relative to the file currently being processed, which makes nested template structures practical.
@input('templates/partials/footer.html')
Nift makes reuse cheap, but ordinary HTML is still fine. A fragment that appears once and reads clearly does not need to become a partial just because it can.