<" /> <" /> <"/>

How to bind data to attributes inside an array of objects using the Plates templating engine?

66 views Asked by At

Using Plates, with their changing sintaxes (this doesn't work anymore) over the years and poor documentation,

I have this string:

<table id="group">
  <tr>
    <td class="name"></td>
    <td>
      <a class="surname"></a>
    </td>
  </tr>
</table>

And this data:

{
  group: [{
    name: 'Ludwig',
    surname: 'von Mises',
    url: 'http://mises.org/'
  }, {
    name: 'Friedrich',
    surname: 'Hayek',
    url: 'http://hayek.org/'
  }],
}

What should I do to bind url to href, so I get

<table id="group">
  <tr>
    <td class="name">Ludwig</td>
    <td>
      <a class="surname" href="http://mises.org/">Mises</a>
    </td>
  </tr>
  <tr>
    <td class="name">Friedrich</td>
    <td>
      <a class="surname" href="http://hayek.org/">Hayek</a>
    </td>
  </tr>
</table>

?

1

There are 1 answers

0
fiatjaf On

Faced with a simple problem with others' libraries, I did what any programmer would do in this case: I wrote my own Plates-like (but not a fork of it) templating engine that (maybe) works.

Here it is: https://github.com/fiatjaf/tempreites

(Works with strings, semantic binding, just one file, no dependencies, a simple synchronous function named render and it is it.)

(I began writing it after I posted this question here, so it wasn't just for the propaganda.)