Example

Share via

The example shortcode displays a code example and renders a preview of the same input.

Overview

The example shortcode displays a code example and renders a preview of the same input. The shortcode accepts the languages supported by Hugo’s highlight function  .

export MY_VAR=123
markdown
{{< command >}}
export MY_VAR=123
{{< /command >}}

Arguments

The shortcode supports the following arguments:

ArgumentRequiredDescription
idNoOptional identifier of the element’s container.
langNoLanguage used to display the code. Use “hugo” to process Hugo (escaped) shortcodes, default value is “html”.
show_markupNoIf the markup should be output in the HTML, defaults to “true”.
show_previewNoIf the preview should be output in the HTML, defaults to “true”.
classNoOptional class attributes of the element’s container.

Examples

Change the style and language of your code snippet with shortcode arguments.

Hugo code example

Set the lang argument to hugo to render a Hugo code example. Be sure to escape the input with /* and */ delimiters to avoid rendering issues.

Preview

export MY_VAR=123
markdown
{{< command >}}
export MY_VAR=123
{{< /command >}}

Input

{{< example lang="hugo" >}}
    {{</* command */>}}
    export MY_VAR=123
    {{</* /command */>}}
{{< /example >}}

Hidden markup

Set show_markup to false to hide the code input and to display the preview only.

Preview

This is a lead paragraph. It stands out from regular paragraphs.

Input

{{< example show_markup=false >}}
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}
{{< /example >}}

Hidden preview

Set show_preview to false to hide the output and to display the code input only.

Preview

markdown
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}

Input

{{< example show_preview=false >}}
This is a lead paragraph. It stands out from regular paragraphs.
{.lead}
{{< /example >}}
Last updated: September 2, 2023 • Convert to markdown only (6581c88)