Mohsin Younas Mohsin Younas - 6 months ago 23
Node.js Question

How to Use the values of one local variable in replacement of other in HandleBarjs

I am facing and issue with the handle bars.

I have created two local variable with the name of the language and which corresponds the path of two Json files.


I am detecting the de or en from the URL and storing into another local variable call "Lang"

app.locals.lang = "Some code that detects DE or EN from URL and Stores into

Now in the Handlebrsjs I am using something like


The Lang above should give De or EN which it is giving but the it does not goes to the Json file but if we simply use


It works fine.
I want to use lang.home.title instead of en.home.title becs the lang also have the same value that is en.
But it does not work with lang.home.title

There must be some way to solve the problem. Please tell me. Thank you.

Answer Source

Try this: = {};'../locales/en.json');'../locales/de.json'); = "Some code that detects DE or EN from URL and Stores into 


You should then be able to do the following in your template:


I hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download