Using kraken.js (an express.js framework) I'm building a localized website. In the header, there are 3 links to change the language
FR | EN | DE
If the locale is set to FR (according to a cookie) I would like to have the FR link underlined (with a class="active"
attribute in html). Sadly, I can't find where to add this behavior. Do I have to use a frontend script or can I add this behavior in dust.js (included in kraken.js) ?
You can add it in dust -- but you're going to have to dig a bit or build middleware to copy the value to where dust can see it.
From the
krakenjs-examples/with.i18n
project, itslib/locale.js
middleware:module.exports = function () { return function (req, res, next) { var locale = req.cookies && req.cookies.locale; //Set the locality for this response. The template will pick the appropriate bundle res.locals.context = { locality: locale }; next(); }; };
That puts it on
res.locals
where dust can find it.