Open navClose nav

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.

Example

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 %}}

At this time, there is no specific convention for identifying which parts of your snippet can be customized when the snippet is applied inside the editor. We recommend simply using descriptive placeholders, such as “Tip Body” in the example above.

Using Snippets

You can access the list of available snippets by clicking the { } snippet icon in the editor toolbar.

https://res.cloudinary.com/forestry-demo/image/fetch/c_limit,dpr_auto,f_auto,q_80,w_640/https://forestry.io/uploads/2018/07/snippet.png

Clicking on a snippet in the list will insert its contents into your document at the cursor position.


Last updated on July 20, 2018