Skip to content

Instantly share code, notes, and snippets.

@panoply
Created April 20, 2019 21:53
Show Gist options
  • Save panoply/a98b52041756d84567d9b1f4946f646a to your computer and use it in GitHub Desktop.
Save panoply/a98b52041756d84567d9b1f4946f646a to your computer and use it in GitHub Desktop.

DatoCMS Navigation

For Jekyll users who want a simple solution for creating navigation menus using DatoCMS. Use a Links model in the CMS and It will output the following data file under the Navigation model:

footer-menu:
- title: Amsterdam, Center
  url: amsterdam-center
- title: Amsterdam North
  url: amsterdam-north
- title: Amsterdam, West
  url: amsterdam-west
- title: Amsterdam, South
  url: amsterdam-south
main-menu:
- title: Home
  url: home
- title: Products
  url: products
- title: Contact
  url: contact
  

This means you can access each menu in a simple liquid foreach loop:

<ul>
  {% for item in site.data.navigation.main-menu %}
    <li>
      <a href="{{ item.url }}">{{ item.title }}</a>
    </li>
  {% endfor %}
</ul>
# Navigation
create_data_file("data/navigation.yml", :yaml,
dato.navigations.each_with_object({}) do |nav, navigation|
navigation[nav[:name].parameterize] = nav[:menu].map do |item| {
title: item.title,
url: item.permalink
}
end
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment