How to compile jade templates in to JavaScript functions to use them on client side?

后端 未结 6 929
清歌不尽
清歌不尽 2021-01-04 11:31

I want to use compiled jade templates on client side. How should I compile them to get javascript files ? https://github.com/visionmedia/jade

6条回答
  •  情话喂你
    2021-01-04 12:13

    This question is a bit dated, but there is a method of compiling Jade templates,

    var jade = require('jade');
    var fn = jade.compile(jadeTemplate);
    var htmlOutput = fn({
      maintainer: {
        name: 'Forbes Lindesay',
        twitter: '@ForbesLindesay',
        blog: 'forbeslindesay.co.uk'
      }
    })
    

    Just got to the tutorial and search for compile, or the API under

     jade.compile(source, options)
    

    Be sure to set, compileDebug so you get the source,

    Set this to false to disable debugging instrumentation (recommended in production). Set it to true to include the function source in the compiled template for better error messages (sometimes useful in development).

提交回复
热议问题