Assemble makes it easy to combine templates, data and content to produce any kind of resulting documents, such as HTML web pages, UI components, styleguides, blog posts, and so on.
TODO
- Templates
- Layouts
- Pages
- Partials (includes)
- Data
- Content
A template is a document or document fragment that contains variables that will be replaced (by the template engine) with actual data, content or other documents.
Assemble has built-in support for the following template concepts:
- Layouts: used to "wrap" pages with common elements, such as site-wide navigation, footers, the
<head></head>
section and so on. - Pages: typically have a 1-to-1 relationship with the actual generated HTML pages in a project, e.g.
about.hbs
=>about.html
orabout/index.html
. But pages can also be dynamically generated from config data. - Partials: document fragments or snippets of code that will be included, inserted or embedded into other templates at build time.
Let's walk through these in more detail.
A basic layout might look something like this:
Pages, generally structural in nature, are optionally wrapped with layouts and contain more HTML than textual content.
A basic page might look something like this:
Partials allow you to define a chunk of code one time and use it in multiple places.
Partials are often used for UI components such as buttons, navbars or modals. But they can also be used for any other snippets or sections of code that might be repeated across multiple pages, or for code that might otherwise be reusable in some way. Partials are easy to spot since they use a >
, which is the special Handlebars.js syntax) that is only used with partials: e.g. {{> foo }}
.
Continuing with the layout
example from above, to use a partial for the head
section simply create a new file, such as head.hbs
or whatever you prefer, then extract the code from the head section and add it to the new file:
Before continuing on, ensure that the filepath to your newly created partial, head.hbs
, is specified in your project's configuration so Assemble can take note of it, ensuring that the partial can be used in your templates.
Now, to actually use the partial, add the {{> head }}
template to the head
section of your layout where the code was removed. Assemble makes this simple by allowing you to use the name of the file you just created as the name of the partial:
Content is usually written in an easy-to-read plain text format such as markdown. Assemble can be extended to convert any format.
Additionally, Assemble can convert your content to HTML according to your preferences:
- Convert 1-to-1 into HTML pages, e.g.
about.md
converts toabout.html
(orabout/index.html
if you use permalinks) - Insert into other pages (as includes)
- Concatenate several content files together before converting to pages or being inserted into (template) pages. assemble.io/helpers/ is a good example of this. Each helper/section on this page is created from more than 100 individual markdown files.
Data from specified JSON or YAML files is made available for use in your templates.
This is best explained through examples, so given we have a partials for generating buttons, button.hbs
:
And given we have a corresponding file, button.json
, with the following data:
[
{
"text": "Success!",
"modifier": "btn-success"
},
{
"text": "Error!",
"modifier": "btn-error"
},
{
"text": "Warning!",
"modifier": "btn-warning"
}
]
When used like this:
Which results in:
<button type="button" class="btn btn-success">Success!</button>
<button type="button" class="btn btn-error">Error!</button>
<button type="button" class="btn btn-warning">Warning!</button>
Beyond using data files to pass to templates as context, they can also be used for global project configuration and setting options. See the documentation for data to learn more.
TODO
- Plugins
- Helpers
- API