pug

iterate over an array of objects in jade/pugjs

…衆ロ難τιáo~ 提交于 2019-12-18 14:52:15
问题 I have the following json object: var partners =[{ "name":"partnerx", "image": "imagex" }, { "name": "partnery", "image": "imagey" }] I want to put into a ul object using jade and I tried: ul#slides.swiper-wrapper mixin partners(name, image) li.swiper-slide img(src=#{image} , alt=#{name}) This is not working. 回答1: Try this: ul#slides.swiper-wrapper each partner in partners li.swiper-slide img(src=partner.image, alt=partner.name) https://pugjs.org/language/iteration.html 来源: https:/

iterate over an array of objects in jade/pugjs

依然范特西╮ 提交于 2019-12-18 14:51:37
问题 I have the following json object: var partners =[{ "name":"partnerx", "image": "imagex" }, { "name": "partnery", "image": "imagey" }] I want to put into a ul object using jade and I tried: ul#slides.swiper-wrapper mixin partners(name, image) li.swiper-slide img(src=#{image} , alt=#{name}) This is not working. 回答1: Try this: ul#slides.swiper-wrapper each partner in partners li.swiper-slide img(src=partner.image, alt=partner.name) https://pugjs.org/language/iteration.html 来源: https:/

Set page title from a child template in Jade

ぃ、小莉子 提交于 2019-12-18 14:48:53
问题 I'm wanting to set my page titles in the child templates of the layout via jade. I don't want to set them in the routes since that requires a server restart. Here's what I'm hoping to accomplish: layout.jade: !!! 5 head - var title = title || "Default Title Here" title #{title} // ... child.jade: - var title = "Child Title Here" extends layout // ... Any thoughts on how I can accomplish this would be a great help. Thanks! 回答1: From https://github.com/visionmedia/jade/issues/654#issuecomment

How to insert raw HTML in Pug file (not include external HTML file)

别说谁变了你拦得住时间么 提交于 2019-12-18 13:09:35
问题 So what I want is to put some multiline HTML into a Pug file and can't find anywhere how to do this. Example: html head body <div><a href="lala"> blabla </a></div> p hihuhohoo 回答1: Pug text can include HTML. Just force it as text, and it should parse: html head body | <div><a href="lala"> blabla </a></div> p hihuhohoo Also, you were using backslashes, not forward slashes, to close elements. 回答2: This is a tested example with passing variables with raw html to the pug file: yourSourceFile.js

nodejs, jade escape markup

冷暖自知 提交于 2019-12-18 12:33:47
问题 I have an Express app using the default Jade view engine. When I try to render HTML as-is in a <pre> element, it gets rendered as actual DOM elements instead of literal characters. h1 Code Sample pre code <div>some text</div> Output: <h1>Code Sample</h1> <pre> <code> <div>some text</div> </code> </pre> How do I escape the HTML so that it gets rendered as follows? <h1>Code Sample</h1> <pre> <code> <div>some text</div> </code> </pre> 回答1: Jade uses the bang to force unescaped output. So you

Jade to HTML converter [closed]

末鹿安然 提交于 2019-12-18 12:10:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have started writing an application using nodejs and jade, but after a while my team decided to switch to Django. I would still like to use the web pages written using jade, without having to re-write them by hand. Does anyone know of a tool that transforms jade code into html? As far as I've seen, most of the

variable in class name jade

♀尐吖头ヾ 提交于 2019-12-18 11:16:36
问题 I can't set a variable name in a class in jade: .flag_#{ session.locale } #{ session.locale } I have: <div class="flag_" >en</div> And I'd like to have <div class="flag_en" >en</div> Thanks 回答1: Try this (have not tested): div(class="flag_#{ session.locale }") session.locale 回答2: As for pug@2.0.0-alpha3 works this way: div(class="flag_" + session.locale) session.locale 回答3: Here's another approach: mixin formButton(text, type, extra_classes) - var default_classes = 'btn btn-primary' if extra

Access element whose parent is hidden - cypress.io

混江龙づ霸主 提交于 2019-12-18 04:36:09
问题 The question is as given in the title, ie, to access element whose parent is hidden. The problem is that, as per the cypress.io docs : An element is considered hidden if: Its width or height is 0. Its CSS property (or ancestors) is visibility: hidden. Its CSS property (or ancestors) is display: none. Its CSS property is position: fixed and it’s offscreen or covered up. But the code that I am working with requires me to click on an element whose parent is hidden, while the element itself is

Jade - convert new lines to <br/> and keep the content encoded

☆樱花仙子☆ 提交于 2019-12-18 04:14:55
问题 I am still not that familiar with the Jade template engine. Is there a way to convert the new lines such as \n to br tags and at the same time keep the other content encoded? For example .replace(/\n/g,'</br>') applied over the encoded value should do the work. However I am not sure how to encode the value and get the result. Is there any helper for this? 回答1: You can use jades escape method and replace the linebreaks in the return value of that like so: p !{escape(foo).replace(/\n/g, '<br/>'

can i use pug (ex-jade) with react framework?

一个人想着一个人 提交于 2019-12-18 03:32:19
问题 i have read some of pug documentation. its said that i have to install pug first and i'm already done that. then i have to require pug in my js file. but i don't know where to write the compile for pug file in my react files? what is the right steps to use pug in react framework? thanks! i really appreciated any help. here is one of my component in react that i would like to render it with pug. import React from 'react'; import Sidebar from './Sidebar'; import Header from './header/Header';