Import external file content into handlebar

TylerD picture TylerD · Feb 1, 2016 · Viewed 12.9k times · Source

I hope someone can give me a hint. I would like to import content from one file into my handlebar file. Is it possible? In my case, it is an css/scss file (e.g. reset.css) which stylings I want to import into my handlebar file (styleReset.hbs).

The "styleReset.hbs" should looks kind of like this:

<style type="text/css">
    <!-- import of reset.css content -->
</style>

P.S. I don't want use the -tag

Answer

Sabunkar Tejas Sahailesh picture Sabunkar Tejas Sahailesh · Apr 29, 2018

Yes, it is possible to import the external css file into your handlebars .hbs file (i.e- Template engine).
Follow these steps :

  • First create a folder public under which place your css folder, which content all your css files. For ex folder structure would be - public/css/style.css (Note: This public folder contains all your static files like css, images, etc)
  • Register your public folder to express in your .js file by app.use(express.static(__dirname + '/public'));
  • Now you can import external css file in handlerbars template file by <link rel="stylesheet" href="../css/style.css">

enter image description here