Is it possible to use it? For example here:
- var movieList = [{title: "Ocean's Eleven", rating: 9.2}, {title: "Pirates of the Caribbean", rating: 9.7}];
mixin movie-card(movie)
h2.movie-title= movie.title
div.rating
p= movie.rating
for movie in movieList
+movie-card(movie)
I don't want to use -
at the start of each line.
If it not possible maybe there is some way to import multiline JSON file?
Variables in pug. There are 4 types of data available in pug which can be stored in pug variables which are explained below : String Variable : Variable stores String value as shown below : //example - 1 var str = "String"; //example - 2 var value = 'This is string type of data' ; Integer Variable : Variable stores Integer value as shown below :
Previous versions of Pug/Jade supported an interpolation syntax such as: a(href="/#{url}")Link This syntax is no longer supported. Alternatives are found below. (Check our migration guidefor more information on other incompatibilities between Pug v2 and previous versions.)
Pug files are marked with ; Jade files are marked with . Make sure the Pug (ex-Jade) and File Watchers required plugins are enabled on the Settings/Preferences | Plugins page, tab Installed, see Managing plugins for details.
Pug (Jade) Template Engine. WebStorm integrates with the Pug (Jade) template engine. Before you start, make sure you have Node.js on your computer. The Pug (ex-Jade) plugin introduces the following changes to the WebStorm UI: The Jade file item is added to the menu. The Pug files are marked with ; the Jade files are marked with .
Since version 2.0.3 it is possible using this syntax:
-
var arr = ["Very", "Long",
"Array"];
Link to pull request: https://github.com/pugjs/pug/pull/1965
You can import JSON data during compile using LOCALS (Jade) or DATA (Pug). This is how I do it via gulpjs and Pug, movieList would be data created in the gulpfile.js and songs.json would be an external file. It's not clear from you code sample if you are using a task manager or express, etc...
gulpfile.js
var fs = require('fs'),
gulp = require('gulp'),
pug = require('gulp-pug'),
movieList = [{title: "Ocean's Eleven", rating: 9.2}, {title: "Pirates of the Caribbean", rating: 9.7}];
gulp.task('markup', function() {
gulp.src('./markup/*.pug')
.pipe(pug({
data: {
// in Jade, this would be "locals: {"
"movies": movieList,
"music": JSON.parse( fs.readFileSync('./songs.json', { encoding: 'utf8' }) )
}
)
.pipe(gulp.dest('../'))
});
});
and in the Pug Template
- var movieList = locals['movies'] // assuming this will eventually be "= data['movies']"
- var musicList = locals['music'] // assuming this will eventually be "= data['music']"
mixin movie-card(movie)
h2.movie-title= movie.title
div.rating
p= movie.rating
for movie in movieList
+movie-card(movie)
mixin song-card(song)
h2.song-title #{song.title}
div.rating
p #{song.rating}
for song in musicList
+song-card(song)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With