bigpipe / pagelet

Pagelets are small re-usable standalone components
MIT License
54 stars 6 forks source link

pagelet.template #16

Closed 3rd-Eden closed 9 years ago

3rd-Eden commented 9 years ago

Add new convenience method which can render templates that are in the same folder as the view of a pagelet is specified in.

It can be possible that you want to do some manual fetching and processing of templates and pass the results of this in to the render callback of your get method.

var React = require('react')
  , Pagelet = require('pagelet')

Pagelet.extend({
  view: 'view.jsx',
  get: function get(render) {
    var pagelet = this;

    var Component = React.createClass({
      mixing: [Intl],
      render: function () {
        // new method
        return pagelet.template('./my-component.jsx', {
          FormattedMessage: React.FormattedMessage
        });
      }
    });

    return render(undefined, {
      Component: Component,
      intlData: { locale: 'us', messages: [{}] }
    });
  }
}).on(module);