wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

extend rt-template for in-component usage #155

Open nippur72 opened 8 years ago

nippur72 commented 8 years ago

Currently rt-template allows to define a component and to pass it via props to the parent component as a factory function (a function that creates an element).

Now such function is available only to the calling element, and not the current element despite it being defined in its scope.

I propose to extend the syntax allowing the factory function to be used in the same component where rt-template appears.

An example:

<div>
   <rt-template arguments="name" function="greeter">
      <button>Hello {name}!</button>    
   </rt-template>

   {greeter('Bender')}
   {greeter('Fry')}
   {greeter('Leela')}
</div>

In the above example function="greeter" tells to not pass the template to props but instead make it available in the current scope with the name greeter.