Aller au contenu

Ekit Template Syntax — Developer Guide (DSL Reference)

This guide documents the Ekit templating language based on Handlebars, with custom helpers for data access, asset resolution, single-record lookup, and partials.


1. Datasources (ekdata)

All template data is exposed through the global object ekdata.

Datasources are declared in the YAML frontmatter:

---
datasources:
  articles:
    from: articles
    limit: 10
---

Usage:

{{ekdata.articles}}

2. Looping with #each

Iterate through a list of items:

{{#each ekdata.articles}}
  <h2>{{this.title}}</h2>
  <p>{{this.description}}</p>
{{/each}}

this refers to the current record.

Field access:

{{this.author}}
{{this.first-name}}

3. Accessing a Single Record (#single)

Declare a datasource returning exactly one object with a UID:

---
datasources:
  featured-article:
    from: articles
    uid: "ARTICLE_UID"
---

Usage:

{{#single ekdata.featured-article}}
  <h1>{{this.title}}</h1>
  <p>{{this.description}}</p>
{{/single}}

4. Partials ({{> partialName}})

Examples:

{{> header}}
{{> components/article-card}}

With context:

{{> card this}}

5. Assets ({{ekasset "path"}})

<img src="{{ekasset "images/logo.png"}}" alt="Logo">

6. Displaying Values

{{this.title}}
{{this.first-name}}

7. YAML Frontmatter Reference

---
layout: default
datasources:
  articles:
    from: articles
    limit: 20

  featured-article:
    from: articles
    uid: "12345"
---

8. Complete Example

YAML

---
layout: default
datasources:
  authors:
    from: authors
    limit: 10

  featured-author:
    from: authors
    uid: "69381978dbccb28748829f17"
---

Template

<h1>Authors</h1>

<ul>
  {{#each ekdata.authors}}
    <li>{{this.first-name}} {{this.lastName}}</li>
  {{/each}}
</ul>

<h2>Featured</h2>

{{#single ekdata.featured-author}}
  <strong>{{this.first-name}}</strong> — {{this.lastName}}
{{/single}}

9. Summary of Ekit Helpers

Helper Purpose Example
#each Loop through a datasource {{#each ekdata.articles}}…{{/each}}
#single Access a single record {{#single ekdata.featured}}…{{/single}}
ekasset Resolve public asset path {{ekasset "images/logo.png"}}
> partial Include a partial template {{> header}}
this Current record in context {{this.title}}