I am learning Node.js for website development.
Previously I could use PHP to include something like a navigation bar on every page, using <?php include('blah.php') ?>
. This works in the same way of me just using the actual code on the page.
My question is: is there any way to import HTML elements / pages from one page to another with JS / Node.js?
Bearing in mind, PHP integrates directly with HTML in the same file, and Node.js does not integrate so seamlessly, so what I'm asking might be impossible.
Asked
Active
Viewed 284 times
-1

Thomas Jowsey
- 47
- 1
- 8
-
1It's obviously not impossible. nodejs is "just" a JavaScript engine, so to use it as web server, people usually use [express](http://expressjs.com/), which in turn uses a templating engine. Switching from PHP to templating can be challenging at first, which is why there are lots of tutorials. Those can be found on the express website, or via Google. – May 30 '18 at 10:06
-
Also: https://stackoverflow.com/questions/11324221/need-to-convert-my-php-app-in-node-js – May 30 '18 at 10:11
1 Answers
0
use EJS - Embedded JavaScript templating.
set delimeter : ejs.delimiter = '?';
<?- include('header'); -?>
<h1>
Title
</h1>
<p>
My page
</p>
<?- include('footer'); -?>

Saurabh Mistry
- 12,833
- 5
- 50
- 71