How to setup reactive variable programatically


#1

I want to know if this is possible:

Say i have:
``

Some Title
`` After some event (after rendering) i want to replace the Text ``Some Title`` with a reactive helper, say ```{{name}}``` or similar.

So it becomes:
``

{{name}}
``

But i don’t want to load the template with that helper. Is there a way to do this?


#2

http://docs.meteor.com/#/full/template_registerhelper


#3

Yes but how should i do it after rendering? Provided it was plain text in the template and not a reactive variable to begin with?

I guess i mean to say is can i use a spacebar variable from jQuery?


#4

Why not start with that helper from start?
If it is just static text than hardcode it in that helper as default value.
Or as default value of reactive source which will be read in that helpers.


#5

Assuming its not possible in this use case, is there a way to do it?


#6

you can directly replace it in DOM using jquery, but saying “not possible” to do it my way sounds strange.
I dont see any reason why you would not be able to do it.

Also you can just replace it with template programatically any time you want by attaching it directly to DOM with Blaze.render()


#7

Thanks for the pointer to Blaze.render() I think that would work pretty well :wink:

I am going to give this a try, i know it sounds strange.


#8
or
{{#if eventHappened }}
  <h5>{{name}}</h5>
{{else}}
  <h5>Default title</h5>
{{/if}}