Snippets
Snippets in Forestry are pre-defined chunks of text that can be inserted into your content. You can put anything in a snippet that you might normally insert into your content, but they are especially useful in conjunction with shortcodes in Hugo or certain Liquid tags in Jekyll.
Creating Snippets
To create a snippet, add a .snippet
file to the .forestry/snippets
directory in your repository. This file should contain the content that you wish to be inserted when your snippet is applied in the editor. You can also embed Markdown in your snippets.
Examples
The Forestry.io website has a Hugo shortcode for adding helpful tips to our blog posts and documentation. To make inserting these easier, we have added a Tip Snippet for inserting that shortcode. Here is the snippet:
.forestry/snippets/tip.snippet
{{% tip %}} Tip Body {{% /tip %}}
Our Markdown editor does not support Markdown tables yet. So you might want to provide a Markdown table starter to help your editors.
A simple .forestry/snippets/table.snippet file:
### Table title
| Header | Header | Header |
| ------ | ------ | ------- |
| Cell | Cell | Cell |
| Cell | Cell | Cell |
| Cell | Cell | Cell |
Using Snippets
You can access the list of available snippets by clicking the { }
snippet icon in the editor toolbar.
Clicking on a snippet in the list will insert its contents into your document at the cursor position.
Caught a mistake or want to contribute to the docs? Edit this page on Github!