SSGO LogoDOCS

Loops

In order to let you build pages and components by iterating over fetched datas inside of you templates, ssgo provides the for / of couple of attributes.

for and of must be used together : an error will be thrown if of the two is missing the other.

For example, let's say that one of your creators is triggering a build page with the following data:

{
  posts: [
    { title: "Blog post number 1", readTime: 22, hide: false },
    { title: "Blog post number two", hide: true },
    { title: "How I built a static site generator for deno", readTime: 120, hide: false },
  ],
}

Then you could for example easily build the list of your posts as follows:

<ul>
  <li
    for="blogpost"
    of="posts"
    eval:data-readtime="blogpost.readTime ?? 0"
    if="!blogpost.hide"
  >
    {{ index + 1 }} - {{ blogpost.title }}
  </li>
</ul>

Your built page would look like that:

<ul>
  <li data-readtime="22">1 - Blog post number 1</li>
  <li data-readtime="120">2 - How I built a static site generator for deno</li>
</ul>

There are some interesting things to notice in this example:


Something about this page is wrong? Edit it on GitHub.