flatiron / plates

Light-weight, logic-less, DSL-free, templates for all javascript environments!
MIT License
831 stars 69 forks source link

Feature: Iteration #11

Closed ghost closed 12 years ago

ghost commented 12 years ago

A common feature in template engines is the ability to iterate through an array to generate multiple lines eg. multiple script tags based on an array with filenames.

This is missing in plates.

mwawrusch commented 12 years ago

+1

I am trying to come up with a good syntax for this. My gut feeling tells me that we should do something like

data-bind='name of array/object to iterate' data-each="name of template'

as a control structure in the html. Plates would basically invoke a custom callback, passing the name of the template, the data object that is in scope, the name and some way to inject text in the rendering stream. The plates consumer could then instantiate a new plates with the template name specified, render the sub template x times, append it to the primary templates output and voila, everyone is happy.

heapwolf commented 12 years ago

@mwawrusch, that goes against the entire concept of the library. html and data MUST be on the passive/receiving end of things. or else its just as bad as any other DSL-dependent templating lib. iteration should be drivin be the data...

javascript

  var html = '<div id="test"></div>';
  var data = { "test": ["First Value", "Second Value"] };

  var output = Plates.bind(html, data);

html output


  <div id="test">First Value</div><div id="test">Second Value</div>
ghost commented 12 years ago

@hij1nx: Great solution! Keeps the HTML prettier :)