How I can use view-template helpers in my code
srigi opened this issue · comments
I'm trying to develop custom view engine for rendering ReactJS templates. I want React to fully control my View, so it will be generating layout. React components are ordinary nodejs code.
How I can call css("my/stylesheet")
in my nodejs code?
Just like that!
var linkTag = css("my/stylesheet");
The asset helpers are registered within the helper context, which defaults to the global scope.
Thanks for answer. Checking this
inside module doesn't crossed my mind. However I don't like this idea much, cos in Javascript this
is very "unstable" object.
I was able to find more explicit solution:
var assets = require('connect-assets');
var middleware = assets({
paths: ['./public'],
});
middleware.options.helperContext.css("my/stylesheet")
Not sure if you’ve seen the option, but you can pass anything in the helperContext
you’d like, if globals make you uncomfortable.
You’ll need to pass that same context object to your views, if you take this approach.