Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template tags support #2

Open
grabbou opened this issue Aug 9, 2014 · 5 comments
Open

Template tags support #2

grabbou opened this issue Aug 9, 2014 · 5 comments

Comments

@grabbou
Copy link
Collaborator

grabbou commented Aug 9, 2014

In addition to our talk:

Its quite hard to accomplish tag parsing the way you proposed, as long as there is no easy way to pass additional template tags to Template.__define__ without rewriting entire html_scanner.

What about creating template helpers, like:

  • {{inheritsHelpersFromTemplate 'template_name'}}
  • {{inheritsEventsFromTemplate 'template_name'}}
  • {{replacesTemplate 'template_name'}}

For copyAs it's not needed as 'pure' idea of having it is to avoid creating HTML file for a view that inherits from abstract one its properties.

I've created sample UI helper for that:

UI.registerHelper('inheritsHelpersFromTemplate', function (tmpName) {
    UI._templateInstance().__view__.template.inheritsHelpersFromTemplate(tmpName);
});
<template name="foo">
    {{inheritsHelpersFromTemplate 'bar'}}
    {{#each photos}}
          <img src="{{images.[0].source}}" />
    {{/each}}
</template>

and it works! 👍

PR?

@aldeed
Copy link
Collaborator

aldeed commented Aug 10, 2014

I worry that they would be reactively re-run multiple times, which would re-replace and re-inherit, potentially overwriting any overrides that were defined between runs.

@aldeed
Copy link
Collaborator

aldeed commented Feb 11, 2015

I still think it would be best to use additional template attributes for this (e.g., <template name="foo" inherits-helpers-from="bar">), but as you said the core packages don't currently make this possible. It would be good to get a final verdict from MDG on whether they're willing to fold this package into blaze/templating packages, or whether we can do a PR to support tracking additional attributes that are added to template tags. Since they now take feature requests on GitHub, I'll submit an issue.

@mitar
Copy link
Collaborator

mitar commented Feb 12, 2015

Some time ago I also create a spaceless which removes all the whitespace. One idea I had then was that this could be simply an attribute on the template as well. So you could do <template spaceless="true">...</template>. In general having custom annotations on the template could be helpful. So PR for any attributions become maybe simple values in template instance. So <template name="test" foo="bar"> would be the same as:

Template.test.created = function () {
  this._foo = "bar";
};

@mitar
Copy link
Collaborator

mitar commented Feb 12, 2015

Or maybe:

Template.test.created = function () {
  this.attrs = {foo: "bar"};
};

@aldeed
Copy link
Collaborator

aldeed commented Feb 12, 2015

Yep, this.attrs is how I was picturing it working, too.

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

No branches or pull requests

3 participants