To learn how to use handlebars with Express, I followed this tutorial and it worked perfectly: https://www.geeksforgeeks.org/handlebars-templating-in-expressjs/
Now, I'm trying to make it work for production. So, instead of rendering the page as it was supposed to, it shows {{demo.name}}, not the name I have for "demo".
I haven't found anything related to Apache server and handlebars. Here's my virtual host configuration:
- VirtualHost /etc/apache2/sites-available/mydomain.com.br.conf :
<VirtualHost *80>
ServerName mydomain.com.br
ServerAlias www.mydomain.com.br
ErrorLog ${APACHE_LOG_DIR}error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
DocumentRoot /var/www/teste_hbs/views
</VirtualHost>
- app.js /var/www/teste_hbs/app.js
import express from 'express';
import hbs from 'hbs';
const app=express();
app.set("view engine", "hbs");
app.set('views', './views' )
let demo = {
name: 'Rohan',
age: 26
}
app.get('/', (req, res) => {
res.render('dynamic', { demo: demo })
})
app.listen(5000);
- dynamic.hbs: /var/www/teste_hbs/views/dynamic.hbs
<!DOCTYPE html>
<html>
<body>
<p>{{demo.name}} is {{demo.age}} years old.</p>
</body>
</html>
The result I'm having for mydomain.com.br/dynamic.hbs:
{{demo.name}} is {{demo.age}} years old.
Thanks for your help!