danielsvane
danielsvane

Reputation: 613

Jade from external source

I want to parse Jade coming from a database. Like from a blog post, where the body is in Jade. Right now I can parse HTML from Jade using:

!= post.body

It works for HTML, but doesn't for Jade. Is there a way to parse the Jade from an external source?

Upvotes: 0

Views: 223

Answers (1)

Aleksei Zabrodskii
Aleksei Zabrodskii

Reputation: 2228

If you are trying to compile text-string as Jade template (post body from database):

// node.js
// https://github.com/visionmedia/jade/#a5
var jade = require('jade');
var template = 'h1 Hi';
var options = {};

var htmlFunc = jade.compile(template, options);
var locals = {};
var html = htmlFunc(locals);

// now you can pass `html` to your blog post layout.


You can compile Jade string within a template. That's odd, but anyway:

h1!= require('jade').compile('span Hi')();

Upvotes: 2

Related Questions