Contents

Learning New Tricks

Contents

I never had a hobby. If someone’s ask me if I have a hope right now I might say I do and it is creating little projects to learn new things on the web. My latest learning was Eleventy a static generator website built in Node / Javascript.

One thing that I loved about Eleventy is the global data files. They are a easy way to add any data to your pages. You can simply create a JSON files and place in the _data folder and then access in your templates.

Let’s say you have a json files that looks like this:

[
  {
    "blog": "Blog Name 1",
    "author": "Author Name 1",
    "url": "https://www.example1.com"
  },
  {
    "blog": "Blog Name 2",
    "author": "Author Name 2",
    "url": "https://www.example2.com"
  },
  {
    "blog": "Blog Name 3",
    "author": "Author Name 3",
    "url": "https://www.example3.com"
  }
]

All you have to do is to save it for example as blogs.json and place it in the _data folder and now access it in your template you access it like this:

    <ul>
      {%- for blog in blogs %}
      <li>
        <h3>{{ blog.blog }}</h3>
        <p><b>Author:</b> {{ blog.author }}</p>
        <p><a href="{{ blog.url }}</a></p>
      </li>
      {% endfor%}
    </ul>

It is super simple like that and people is using it around the web, one places that I’ve seen it recently was the Default’s list and this really nice modern CSS website StyleStage.