Reusable code: snippets

Let's create a sidebar snippet. Use the command line generator to create a snippet:

bundle exec wagon generate snippet sidebar

You will be asked if you prefer HAML template: if you're not familiar with HAML, answer 'n'.

You will also be asked if you want a localized template: answer 'n'.

A snippet file will be created.

+- app/views
    +- pages
        +- index.liquid
    +- snippets
        +- sidebar.liquid

In sidebar.liquid:

<div id="sidebar">
  the sidebar

Including the sidebar in a template:

    <title>Snippet example</title>
    <div id="content">
      Page content
    {% include 'sidebar' %}

Learn more:

© 2023 LocomotiveCMS Terms of use Privacy Policy
Back to top