Saad
Saad

Reputation: 53939

Read all code from a .js file and insert into a jade template?

Hi all I'm basically trying to make a kind of code comparison thing in a website, so I want to have two snippets of code side by side. Just putting it manually into the Jade template doesn't seem like the best idea, so I was wondering if there was a way I could read in regular JS files and put it into the template.

Basically looking for something like this:

foo.js

var foo = 'foo';
console.log(foo);

bar.js

var bar = 'bar';
console.log(bar);

template.jade

pre
  code
    // Somehow get all of foo.js code here

pre
  code
    // Somehow get all of bar.js code here

Any help would be greatly appreciated.

Upvotes: 0

Views: 39

Answers (1)

Marko Gresak
Marko Gresak

Reputation: 8217

Yes, you can use include. For example:

pre
  code
    include foo.js

Of course you'll have to use correct relative path to the script, if the template.jade and foo.js aren't in the same folder.

Upvotes: 1

Related Questions