Snippets are common blocks of HTML or text that can be used globally across all templates. Some clever uses included:
- Reusing Common headers and footers across templates
- Reusing Common CSS
- Keeping a “library” of jinja macros to be reused throughout templates
How do I use snippets?
Create a snippet in the Snippets) section.
In your template, reference the snippet by snippet name in the template:
Can I use snippets within snippets?
Yes! Nested snippets are supported.
Can variables be used in snippets?
Yes! All data that can be referenced in a template can be referenced in a snippet. For example:
Snippet - Link
Can snippets be given variables like a function?
Snippets don’t take variables. It’s better to use a jinja macro to accomplish that.
Jinja Macro Example
Jinja macros are similar to functions in programming languages. They abstract a block of commonly used code and can be set up to accept modifications when called.
Snippet - Macro Example
For more information on Jinja Macros and other examples, visit the official Jinja documentation.