Skip to content

Instantly share code, notes, and snippets.

@afeld
Created November 10, 2016 06:47
Show Gist options
  • Save afeld/2320f6067df8bc9b920d647325c4eeaf to your computer and use it in GitHub Desktop.
Save afeld/2320f6067df8bc9b920d647325c4eeaf to your computer and use it in GitHub Desktop.
attribute lists in Hugo (static site generator)

To create Kramdown-style attribute lists for adding HTML classes around blocks of Markdown, you can leverage Hugo shortcodes.

  1. Add the following to layouts/shortcodes/wrap.html:

    <div class="{{ range .Params }}{{ . }} {{ end }}">
      {{ .Inner }}
    </div>
  2. In your page, use the shortcode, and pass the class names.

    {{% wrap "outer-class" anotherclass %}}
    This is the inner text.
    {{% /wrap %}}

The resulting HTML should be

<div class="outer-class anotherclass ">
  <p>
    This is the inner text.
  </p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment