pug

Jade converts & to & when JavaScript is used

£可爱£侵袭症+ 提交于 2020-06-28 08:14:18
问题 I've just started using Harp 0.30.1 which comes with Jade installed as a pre-processor. So I'm just starting with Jade, too. I have a folder containing a set of files with filenames like This-is-an-MD-file.md . With the index.jade file in this folder, I want to produce the following HTML output: <ul> <li><a href="This-is-an-MD-file.html">This is an MD file</a></li> </ul> I have understood enough about Jade and mixins to produce this... - var trim = function(string) { - var index = string

How to pass a Pug JSON object to client side JavaScript

我与影子孤独终老i 提交于 2020-06-27 13:04:11
问题 I am trying to pass a JSON object from pug to client side JavaScript. Here's how the code is structured. I render a JSON object and pass it to Pug from my Node-Express backend. Code below: server.js : app.get('/myrooms', function(req, res) { Room.find() .where('_id') .in(user.rooms) .exec(function (err, records) { res.render('rooms/index', {myrooms : records}) }) }) After that this object is available in my pug file. Now I want to pass it to a client side script. I am doing something like

How to set source of the image a variable in a pug template?

筅森魡賤 提交于 2020-06-23 14:01:26
问题 While creating a movie info platform, I wanted to print image posters. I was unable to set the source of the image to a variable in pug. each movie in movies .col-md-3(style="margin-bottom: 20px;") .text-center img(src= "#{movie.Poster}" style="width:100%; height:200px; padding: 0px 40px;") h5(style="padding: 5px 40px 0px 40px;") #{movie.Title} h5 #{movie.Year} 回答1: If you have image source stored in movie.Poster , then I think you should try something like this: img(src=movie.Poster) You can

How to set source of the image a variable in a pug template?

大城市里の小女人 提交于 2020-06-23 14:01:10
问题 While creating a movie info platform, I wanted to print image posters. I was unable to set the source of the image to a variable in pug. each movie in movies .col-md-3(style="margin-bottom: 20px;") .text-center img(src= "#{movie.Poster}" style="width:100%; height:200px; padding: 0px 40px;") h5(style="padding: 5px 40px 0px 40px;") #{movie.Title} h5 #{movie.Year} 回答1: If you have image source stored in movie.Poster , then I think you should try something like this: img(src=movie.Poster) You can

Set “basedir” option for Pug in NestJS

陌路散爱 提交于 2020-06-01 09:33:08
问题 I'm trying to use pug layouts in NestJS , however when extending a layout from an absolute path, pug requires the basedir option to be set. In ExpressJS you would use app.locals.basedir = ... , what would be the equivalent in NestJS? const server = await NestFactory.create<NestExpressApplication>(AppModule); server.setViewEngine('pug'); server.setBaseViewsDir(join(__dirname, 'templates', 'views')); await server.listen(config.server.port); Using extends /layouts/index in a view would throw the

Absolute path in PUG

六眼飞鱼酱① 提交于 2020-05-28 04:44:28
问题 According to the PUG documentation (https://pugjs.org/language/includes.html): If the path is absolute (e.g., include /root.pug), it is resolved by prepending options.basedir. Otherwise, paths are resolved relative to the current file being compiled. Which I understand consists of passing the path preposition as an option to res.render(). However, I want to avoid the trouble of repeating myself as much as I can and would prefer a top-level solution. I tried using app.locals.basedir but my

Jade ternary operator add element

…衆ロ難τιáo~ 提交于 2020-05-25 07:41:45
问题 Wondering if there is a way to write a ternary, or shorter form of if statement, which adds the 'a' element to the table cell when the if is satisfied. I tried this, but it doesn't work: td= foo.x ? a(href="/#{foo.x}/foobar") View : '-' The following does work, but is quite long winded and untidy.. tbody each foo in bar tr td= foo.name if foo.x td a(href="/#{foo.x}/foobar") View else td - if foo.y td a(href="/#{foo.y}/hello") Hello else td - Thanks 回答1: No. There is no ternary operator (that

How to allow filtering of plain-text into HTML tags in NodeJS and PUG?

梦想与她 提交于 2020-05-17 08:46:59
问题 I have a web application in NodeJS and PUG/Jade. I want to separate the logic of the application, controlled by a developer, from the textual content, controlled by a marketing person and translators, while keeping all the source code integrated. (I asked about ways for this separation here and got no answers as of this writing). For English, I use a JSON object en.json with: { "404": { "notFound": "Page not found" } } the controller loads it with: let localText = require('./en.json'); res

Multipart form data post method using express js

两盒软妹~` 提交于 2020-05-14 11:59:30
问题 I tried to post form data to my express js server side. This is my pug file form(action="/profile" method="post" enctype="multipart/form-data") input(type="file" accept="image/*" name="profileimage") input(type="text" name="username") input(type="submit" value="Upload") After that I tried to log the post data with req.body inside server side js as follow. That is my profile.js router.post('/', function (req, res) { console.log('Body- ' + JSON.stringify(req.body)); }); And this is my console

Multipart form data post method using express js

佐手、 提交于 2020-05-14 11:57:08
问题 I tried to post form data to my express js server side. This is my pug file form(action="/profile" method="post" enctype="multipart/form-data") input(type="file" accept="image/*" name="profileimage") input(type="text" name="username") input(type="submit" value="Upload") After that I tried to log the post data with req.body inside server side js as follow. That is my profile.js router.post('/', function (req, res) { console.log('Body- ' + JSON.stringify(req.body)); }); And this is my console