express-view-switcher
switch the view root directory per request
How to install
npm install -S express-view-switcher
Usage
1: for multi-device support
; const app = ;app;app; // ...then call res.render() as usual
2: for multi-language support
app;
3: for both multi-device + multi-language support
app;
specify root directory
// if you're using a template engine that supports inclusion or inheritance, and can specify and set the base directory root key name in res.locals,// you can set this root key by passing it as the second argumentapp; // if using Pug as your template engine, there's no need to specify the root key name, as "basedir" is automatically set in res.locals
Practical example
app; /** * get request header * @param * @param * @param * @return */{ if!reqheaders return ""; return reqheadersname;} /** * list up language candidates * @param * @return */{ const acceptLanguage = ; const languageCandidates = ; forconst language of acceptLanguage const parts = language; languageCandidates; // finally, push the default language languageCandidates; return languageCandidates;} /** * list up device candidates * @param * @return */{ // get device info from UserAgent const userAgent = ; return "default";} /** * detect device from UserAgent * @param * @return * @private */{ ifuserAgent !== -1 return "smartphone"; ifuserAgent !== -1 return "smartphone"; ifuserAgent !== -1 return "tablet"; ifuserAgent !== -1 ifuserAgent !== -1 return "smartphone"; else return "tablet"; return "default";}
Changelog
See CHANGELOG.md.