Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic content in html files, node

Tags:

node.js

im new to node and i've searching ways to add dynamic data into html files, like php:

<?php echo $data; ?>

i've found that jade seems to be the exact way for node, but seems to be a little confusing, isn't there a way bit more like php?, something like:

{{data}} where data is var data or function, 
-data- where data is var data or function,
etc.

PD: im new to node and javascript, but i have experience on php, so any tutorial or book to do so will be appreciated

like image 543
Oscar Reyes Avatar asked May 02 '26 22:05

Oscar Reyes


1 Answers

i recommend using Swig js and it does exactly what you are asking for, just pass the variables from the node server, in express js i use it like this:

res.render('index.html', {'name': 'mecha'});

then in my index.html i would just use:

<p>{{ name }}</p>
like image 53
shehata Avatar answered May 04 '26 12:05

shehata