Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an include file into a Handlebars layout

I'm using Node.js, Express 4, and the Handlebars templating processor. Some of the page views that I'm rendering with Handlebars have several kBytes of static inline SVG code. Is there a simple clean way to put the SVG code into a separate file to be included in the Handlebars layout template? Ideally this include file would have a .svg extension, but .hbs would be acceptable.

like image 593
natesrc Avatar asked Oct 21 '25 01:10

natesrc


1 Answers

yesterday I was solving the the same problem. And I finished with loading svg file into string and then pass it to the handlebars template.

var svgTemplate = fs.readFileSync('./public/app/build/images/spriteAll.svg', 'utf8');

var express = require('express'),
    router = express.Router();

router.get('/',  function (req, res) {
    res.render('main', {
        svgTemplate: svgTemplate
    });
});

//where main.hbs contains: ...

<body class="ng-cloak">
    <div class="inline-svg">
        {{{svgTemplate}}}
    </div>
....
</body>
like image 140
Romick Avatar answered Oct 23 '25 14:10

Romick