T
T
Talga UTB2014-09-23 20:56:21
JSON
Talga UTB, 2014-09-23 20:56:21

How to use json data in jade ?

Hello,
does anyone have an example of using data from a json file in jade?
compiled via gulp

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kulakowka, 2014-09-25
@talgautb

See my example: https://github.com/kulakowka/kulakowka.com/blob/ma...
Specifically, in this place. The config variable is passed to the jade template engine.

// Templates
gulp.task('templates', function() {
  
  var config = {
    revision: new Date().getTime()
  };    

  gulp.src('./assets/views/**/*.jade')
    .pipe(jade({
      locals: config
    }))
    .pipe(gulp.dest('./public/'))
    .pipe(notify({ message: 'Templates task complete' }));
});

Nothing prevents you from doing this:
// Templates
gulp.task('templates', function() {
  
  var config = require('./config.json');

  gulp.src('./assets/views/**/*.jade')
    .pipe(jade({
      locals: config
    }))
    .pipe(gulp.dest('./public/'))
    .pipe(notify({ message: 'Templates task complete' }));
});

Well, put the necessary data in the config.json file.
{
  "param1":"мои данные 1",
  "param2":"мои данные 2"
}

Well, in general, the answer is simply searched by a search engine for Gulp Jade .
If you are too lazy to search, then I did it for you.
https://www.npmjs.org/package/gulp-jade
jade-lang.com
There are examples :) I think it should be clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question