kirbysayshi / vash

Vash, the 60 billion double-dollar template-maker. Razor syntax, for JavaScript templates
Other
522 stars 60 forks source link

Are vash.helpers meant to be set server side or template side? #76

Closed grofit closed 9 years ago

grofit commented 9 years ago

I am trying to get NewRelic page loading timers into my vash templates so as the newrelic object lives in the server I thought it would be a good reason to use helpers:

So I put this in my server side code:

vash.helpers.withPageLoadingTimers = function(){
            return app.get("newrelic").getBrowserTimingHeader();
        };

Now if I call this in the template:

@html.withPageLoadingTimers()
<blah>etc</blah>

It just blows up saying that object is not a function, so I am assuming the helper has not connected up correctly, but when reading the docs it kinda implies that the logic for helpers comes from a script file or script tag, which would exist within the template.

So can helpers be used the way I am showing above, if not is there a way I can pass the content of getBrowserTimeingHeader into the templates without explicitly putting it on each model?

kirbysayshi commented 9 years ago

Vash helpers need to be present in whatever context a template is being rendered within. So if you're doing clientside rendering of vash templates, then those helpers need to be registered with the clientside vash runtime.

I'm not sure how you're generating your clientside bundle. But whenever you include the vash runtime is the time when you'd also create a helper that outputs a static new relic string.

kirbysayshi commented 9 years ago

I'm going to close this, but feel free to reopen if you'd like more help!