The render plugin enables your application to handle server-side rendering (currently) using nunjucks, extending the default action and intent classes.
# install the plugin npm i --save thorin-plugin-render@1.x # install nunjucks npm i --save nunjucks@2.4.2
'use strict'; // app.js entry file const thorin = require('thorin'); thorin.addPlugin(require('thorin-plugin-render')); // <-- add this line thorin.run((err) => {});
# run once to allow the plugin to set itself up node app.js --setup=plugin.render
thorin.root
thorin.root
pluginObj.addLocal({some: 'object'})
merge the given object with the global locals
pluginObj.addLocal('aKey', 'aValue')
add the given key to the global locals object.
swig
or html
templates that have access
to rendering utilities and the intent
object.
error
requests or specific status codes
.
'use strict';
thorin.dispatcher
.addAction('my.action')
.alias('GET', '/home')
.render('home.swig') // render the home.swig template by default
.render('error.swig', 500); // render the error.swig template on 500 errors
// You can also select the template dynamically, based on the incoming intent
thorin.dispatcher
.addAction('account')
.alias('GET', '/admin/:type')
.input({
type: dispatcher.validate('STRING')
})
.render('invalid_type.swig', 400) // render this when no type is given
.render('error.swig', 'error') // when other any kind of error occurs.
.render((intentObj) => { // conditional rendering
let type = intentObj.input('type');
if(type === 'app') return 'app.swig';
return 'dashboard.swig';
});
render
render
action event will be triggered,
therefore you can inject functionality before and after the rendering.
fn(intentObj)
, before we begin rendering the templatefn(intentObj, html)
, after the HTML output was generated.thorin.config
config.cdn
setting.
/public
folder.
?v={version}
in the querystrin of the asset.
If it is set on true
, extract the version from the project's package.json file.
result
param
<div class="{{ isAction('home.index','active') }}">Home menu item.</div>
You can always create a new issue on GitHub or contact one of the core founders by chat.