Thanks for the feedback. Underlying mechanism describes it pretty well I believe.
I found a workaround for my problem but there must be a more elegant solution to it. I put together a bit more of my code to explain my question better (hopefully).
My html looks like this:
{{> form}}
{{#with data}}
{{#if data_available}}
{{#each this.rows}}
<div class="css_form_wrapper">
{{>Template.dynamic template=this.template data= this}}
</div>
{{/each}}
{{/if}}
{{#unless data_available}}
<div>
Loading Data
</div>
{{/unless}}
<div>
<button class='button'>Refresh</button>
</div>
{{/with}}
{{#with data}}
{{/with}}
The if / unless part is just there so that when I change data_availability the element templates get destroyed and when I have data i can make sure that the default value in the input element gets reloaded because the template gets rendered.
Without that condition the data helpers get executed and the data the template has is the backend data but the input element will still show whichever value the user entered (As far as I understand because it gets stored in the DOM, right?, but to be honest I dont understand it )
Is there maybe a better way to rerender a specific template?
This is the javascript to it, it simulates a backend call for the data.
var form_tracker = new Tracker.Dependency;
var backend_tracker = new Tracker.Dependency;
var data_available = true;
Template.form.helpers({
data: function () {
var data = _readData();
return data;
},
data_available: function () {
return data_available
}
});
Template.form.events({
‘click .button’:function(){
data_available = false;
_readBackendData();
form_tracker.changed();
}
});
var _readData = function () {
form_tracker.depend();
backend_tracker.depend();
if(backend_tracker.data != undefined) {
return backend_tracker.data
} else {
return {rows: [{‘template’: ‘element’, ‘value’ : ‘no data initially’}]};
}
};
var _readBackendData = function () {
Meteor.setTimeout(function() {
backend_tracker.data = {rows: [{‘template’: ‘element’, ‘value’ : 123}, {‘template’: ‘element’, ‘value’ : ‘’}]};
backend_tracker.changed();
data_available = true;
}, 800);};
Template.element.helpers({
data: function () {
var data = this;
return data;
}
});
This workaround becomes super tedious if just parts of the template get refreshed so I hope somebody can point me in a more elegant direction. Thx