Templates
Templates
basecoat-cli is deprecated
Template files now ship with basecoat-css. If you previously copied templates with basecoat-cli, install basecoat-css instead and copy the files from node_modules/basecoat-css/templates.
Basecoat ships optional Nunjucks and Jinja macros for components with larger HTML structures. They generate the same semantic Basecoat markup shown in the component docs, while keeping repeated server-rendered markup easier to maintain.
The templates are versioned with basecoat-css, so the generated markup matches the CSS and JavaScript files you installed.
Macros
Some macro files include internal recursive helpers such as render_select_items(). Those helpers are implementation details and are not part of the public API.
Usage
Install Templates
Copy the template folder for your template engine from basecoat-css. Templates are meant to be app-owned, so you can edit them after copying.
cp -R node_modules/basecoat-css/templates/nunjucks ./templates/basecoatcp -R node_modules/basecoat-css/templates/jinja ./templates/basecoatCopy only the files you use if you do not want the full template folder.
You can also copy the Nunjucks templates or Jinja templates from GitHub.
Use a Macro
Import a macro from the copied template file, then call it with the props for that component.
{% from "basecoat/select.njk" import select %}
{{ select(
name="fruit",
items=[
{ value: "apple", label: "Apple" },
{ value: "banana", label: "Banana" },
{ value: "blueberry", label: "Blueberry" }
]
) }}{% from "basecoat/select.html.jinja" import select %}
{{ select(
name="fruit",
items=[
{ "value": "apple", "label": "Apple" },
{ "value": "banana", "label": "Banana" },
{ "value": "blueberry", "label": "Blueberry" }
]
) }}