is it possible to apply and access extra attributes to a <template> tag?
e.g.
<template name="foo" color="blue">
later on, access the color attribute from anywhere in the code
is it possible to apply and access extra attributes to a <template> tag?
e.g.
<template name="foo" color="blue">
later on, access the color attribute from anywhere in the code
It depends on what you mean by âanywhereâ. Within the Template callbacks you are able to access these attributes, e.g.
Template.foo.rendered = function() {
var name = this.data.name;
var color = this.data.color;
... do something here ...
}
Thanks for the reply, but thatâs incorrect.
these attributes are available when you include a template and specify data context:
{{> foo color="blue" }}
but that isnât the case.
I have a use case of traversing the view tree, inspecting the templates and looking for a certain template (not even an instance of it)
Iâd like to use an extra attribute on the template tag in order to do that inspection
Initialize an array in your lib:
myTemplates = [];
and within your code, whenever you create a new template, do something like:
myTemplates.push({name: 'myNewTamplate', property:'specialTemplate' });
or just use the original array as a reference and type in the template names there, I find this method easier for keeping track of a modularized structure
Then whenever you need to access the templates that are specialTemplate
s refer to them like:
_.each(_.where(myTemplates, {property: 'specialTemplate'}), function(template) {
Template[template.name].events({
'click': function(e) {
console.log('You clicked somewhere on: ' + template.name + ' template.');
}
});
})
Of course, you can use the wonderful https://atmospherejs.com/aldeed/template-extension package to manage, access and manipulate your templates on the fly.
interesting suggestion, but this wouldnât work for a general solution (package)
thanks though
Iâm happily mixing Polymer and Meteor templates in my project and it works fine. So thatâs always an option to make this work, too.
@rdrey sadly, spiderable doesnât like Polymer (PhantomJS has problems with webcomponents.js)
so I had to drop Polymer, which seemed promising for all my UI needs
also, Polymer is still very experimental outside Chrome (read performance issues or unexpected behavior requiring tedious crossplatform testing), so I wouldnât recommend it for production
Oh damn, thanks for the warning @chenroth ⌠I havenât tried out spiderable yet. (But have read about it.) Large parts of my app I donât want to be crawled, though.
Would spiderable work if I keep just a few pages like the homepage âPolymer freeâ? According to this issue Polymer in PhantomJS is still quite far from done.
Thanks for the https://prerender.io/ tip, @serkandurusoy. It seems a bit pricy, but might be worth it. I really like the encapsulation that Polymer components give me - otherwise I should probably switch to React soon.