There are two ways to register variables: you can either register them after the template is created but before render() is called (as is done with my_str and my_arr in your example), or you can use preRegister(), which has to be done before the template is rendered. I think the reason for preRegister is mostly because without it, there would need to be a hook location everywhere a template is rendered, or else you couldn't add variables to the existing vb templates.
So the reason your code doesn't work is because you have the call to preRegister() after the template is rendered. But since you are creating and rendering your own custom template, you should just use a call to register.
BTW, I should have explained this better when answering in your other thread, so sorry about that.
|