mikado icon indicating copy to clipboard operation
mikado copied to clipboard

How includes work / can we shift data context for includes?

Open OndrejValenta opened this issue 8 months ago • 0 comments

Hi, I'm just playing with Mikado and I'm actually confused how includes work.

For this data..

{
    "header": "List of users",
    "users": [
        {
            "username": "User A0",
            "tweets": [
                "foo",
                "bar",
                "foobar"
            ]
        },
        {
            "username": "User A1",
            "tweets": [
                "foo",
                "bar",
                "foobar"
            ]
        }
    ]
}

I've created header.html that looks like this

<h1>{{data.header}}</h1>

row.html as a partial that looks like this

<tr>
  <td>{{ data.username }}</td>
  <td>{{ data.tweets.length }}</td>
</tr>

and list.html that looks like this

<div>
  <div include="build/partials/header"></div>
  <table>
    <thead>
      <tr>
        <th>User</th>
        <th>Tweet count</th>
      </tr>
    </thead>
    <tbody include="build/partials/row"></tbody>
  </table>
</div>

Questions:

  • is there a way to set a context for include, like context=data.users?
  • it seems include is only for enumerables, is there a way to have a "static" component?

Bug:

  • if I put include in table or even tbody tag, whole template is rendered for all rows, including header, is that a desired behavior? Or am I missing something?

OndrejValenta avatar Jun 15 '24 02:06 OndrejValenta