{{< snippet >}}

Description#


The snippet shortcode allows to write a code fragment, defined either from the shortcode content , or from a template file.

Moreover, it is possible to define snippets organised in tabs. To do so, nest as many tab shortcode as needed in a parent snippet shortcode.
For example: display CLI commands depending on the operating system used.

The content as well as parameters defined in a tab shortcode take precedence over definitions in the parent snippet shortcode. If all tabs share the same parameters, it is therefore possible to define them globally in the parent snippet shortcode (cf. examples below).

Parameters#


NameType(named/positional)Description
filenamedFile path to include.
NB: The file parameter takes precedence over the content of the shortcode.
typenamed

File format to include.
Possible values:

  • code
  • md
  • plaintext

NB: If not specified, the default type is code.

captionnamedCode snippet caption.
NB: Parameter only applicable for a snippet of code type.
codelangnamedCode snippet language.
NB: Parameter only applicable for a snippet of code type.
codeparamnamedCode snippet highlight settings .
NB: Parameter only applicable for a snippet of code type.
titlenamedTab title.
NB: Parameter only applicable for a tab shortcode nested in a snippet shortcode.

Examples#


MarkdownRendering
{{</* snippet */>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /snippet */>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* snippet
    type="code"
*/>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /snippet */>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* snippet
    type="md"
*/>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /snippet */>}}

Hello, World!#


I am a reusable template to include in a page content.

{{</* snippet
    type="plaintext"
*/>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /snippet */>}}
# Hello, World! --- *I am* **a reusable** ***template*** to include in a page content.
{{</* snippet
    file="templates/snippet.en.md"
    caption="I'm a legend"
/*/>}}
I'm a legend
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* snippet
    file="templates/snippet.en.md"
    type="md"
    caption="I'm a legend"
/*/>}}
I'm a legend

Hello, World!#


I am a reusable template to include in a page content.

{{</* snippet
    file="templates/snippet.en.md"
    type="plaintext"
    caption="I'm a legend"
/*/>}}
I'm a legend
# Hello, World! --- *I am* **a reusable** ***template*** to include in a page content.
{{</* snippet
    file="templates/snippet.go"
    caption="I'm a legend"
    codelang="go"
    codeparam="linenos=table,hl_lines=[1,3,\"5-7\"],linenostart=10"
/*/>}}
I'm a legend
10
11
12
13
14
15
16
package main

import "fmt"

func main() {
  fmt.Println("Hello, World!")
}
{{</* snippet */>}}
{{</* tab
    title="code"
*/>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /tab */>}}
{{</* tab
    title="md"
    type="md"
*/>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /tab */>}}
{{</* tab
    title="plaintext"
    type="plaintext"
*/>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /tab */>}}
{{</* /snippet */>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.

Hello, World!#


I am a reusable template to include in a page content.

# Hello, World! --- *I am* **a reusable** ***template*** to include in a page content.
{{</* snippet
    file="templates/snippet.go"
    type="md"
    caption="I'm a legend"
    codelang="go"
    codeparam="linenos=table,hl_lines=[1,3,\"5-7\"],linenostart=10"
*/>}}
{{</* tab
    title="first tab"
    type="code"
    caption="I'm an other legend"
    codelang="go"
    codeparam="linenos=table,hl_lines=[1,3],linenostart=20"
/*/>}}
{{</* tab
    file="templates/snippet.en.md"
    title="second tab"
    codelang="md"
/*/>}}
{{</* tab
    title="third tab"
    type="plaintext"
    caption=""
*/>}}
# Hello, World!
---
*I am* **a reusable** ***template*** to include in a page content.
{{</* /tab */>}}
{{</* /snippet */>}}
I'm an other legend
20
21
22
23
24
25
26
package main

import "fmt"

func main() {
  fmt.Println("Hello, World!")
}
I'm a legend

Hello, World!#


I am a reusable template to include in a page content.

# Hello, World! --- *I am* **a reusable** ***template*** to include in a page content.