Skip to content

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

@OndrejValenta

Description

@OndrejValenta

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions