Skip to content
This repository has been archived by the owner on Mar 5, 2018. It is now read-only.

How to render dynamic templates? #72

Closed
legaev-stas opened this issue Aug 3, 2017 · 3 comments
Closed

How to render dynamic templates? #72

legaev-stas opened this issue Aug 3, 2017 · 3 comments

Comments

@legaev-stas
Copy link

legaev-stas commented Aug 3, 2017

Colleagues, I have a task to create a Glimmer.js component, say, <x-table/>. This component should be exported as Web Component.
The goal is to create unified component that accepts data + config and render all the grid accordingly. Example of config:

[
      {
        heading:'Name',
        sortable: true,
        template: '{{givenName}} {{familyName}}'
      },
      {
        heading:'Actions',
        sortable: false,
        template:'<a href="{{url}}" target="_blank">Learn more</a>'
      }
]

Some of the columns contain mix of data and specific html.

This is how I provide data and config to the table:
<x-table @data={{ data }} @config={{config}}></x-table>

And this is template of the x-table component:

<table>
  <tr>
    {{#each @config.columns key="@index" as |column|}}
      <th class="{{if column.sortable 'sortable'}}">{{column.heading}}</th>
    {{/each}}
  </tr>
  {{#each @data key="@index" as |model|}}
    <tr>
      {{#each @config.columns key="@index" as |column|}}
        <td>HOW CAN I RENDER TEMPLATE FROM CONFIG HERE?</td>
      {{/each}}
    </tr>
  {{/each}}
</table>

I can't understand how to render dynamic templates. I tried <td>{{partial column.template}}</td>, but the helper requires pre-registered template. I can't find any API how to do this.

Please advise how can I resolve the issue.

IMO
Counting on the fact we address markup in the configuration, as for me, then the solution should look something like this:

<x-table @data={{ data }}>
    <column heading="Name" sortable>{{givenName}} {{familyName}}</column>
    <column heading="Actions"><a href="{{url}}" target="_blank">Learn more</a></column>
</x-table>

But Glimmer.js does not have any API to access children components and read the data.
Similar solutions in different component libraries:

It is still open question how to pass the data as object in Web Component but at least question of configuration might be solved in this way for current example.

@legaev-stas
Copy link
Author

The question was addressed to slack chat

@roomle-build
Copy link

@legaev-stas could you summarize what was discussed in the slack channel?

@legaev-stas
Copy link
Author

@roomle-build we need to wait until contextual components will be implemented. But I think after this there are still some questions because contextual component should be predefined and you can't use custom template. Let's wait and see new capabilities.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants