pug

Client-Side templating with nodejs and pug

橙三吉。 提交于 2021-02-16 05:09:40
问题 I have a web app that I'm building that has dynamic widgets being constructed on the client-side. Currently I am using nodejs and pug as my server side templating library, and I like the simplicity of pug. I would like to have a series of small pug files on the server that the client side can use as building blocks to construct the user desired widget. I tried using a previous solution found here: client side server side templating nodejs However, that solution looks like overkill for what I

Resource was blocked due to MIME type mismatch using pug and node

筅森魡賤 提交于 2021-02-13 05:44:10
问题 I'm trying to render a view with an id in the url: router.get('/employee', authController.protect, viewsController.getOverviewEmployee); router.get('/employee/:id', authController.protect, viewsController.getOneEmployee); The /employee works fine, but when I get to the /employee/:id page the css and scripts won't load and the console shows me this error: The resource from “http://127.0.0.1:3000/employee/lib/bootstrap/css/bootstrapmin.css” was blocked due to MIME type (“application/json”)

nodejs express url rewrite?

穿精又带淫゛_ 提交于 2021-02-11 06:55:54
问题 I am new to nodejs and just started learning it. I started with express. Everything's good but have a question not sure if this needs to be URL rewrite or URL redirect. views folder looks like below, (jade files) views - index - news - videos The first page definitely is index, url is localhost:3000. Now I want my news page to be the index page, so when I enter localhost:3000 or localhost:3000/news, I want always to see the news.jade content. but I don't want to duplicate news.jade to index

Pug dynamic image src interpolation

萝らか妹 提交于 2021-02-08 19:29:05
问题 I have stored a dynamic url link into a pug variable #{img}. Now I want to include that variable into my image element. Can anyone help me fill in the blank? #{img} //some dynamic url img(src=" ") //want to set src = #{img} 回答1: do it like this - var img = "img/test.jpg" img(src=img) and read this 来源: https://stackoverflow.com/questions/47483937/pug-dynamic-image-src-interpolation

Pug dynamic image src interpolation

喜你入骨 提交于 2021-02-08 19:24:37
问题 I have stored a dynamic url link into a pug variable #{img}. Now I want to include that variable into my image element. Can anyone help me fill in the blank? #{img} //some dynamic url img(src=" ") //want to set src = #{img} 回答1: do it like this - var img = "img/test.jpg" img(src=img) and read this 来源: https://stackoverflow.com/questions/47483937/pug-dynamic-image-src-interpolation

Iterate over javascript object in pug

淺唱寂寞╮ 提交于 2021-02-08 02:12:35
问题 I've seen a few of these questions but the answers never seem to be clear cut. I need to iterate through a javascript object in my pug view. First time using pug, so I may be missing something obvious. Controller: app.get('/search/:keyword', (req, res) => { scraper .searchDictionary(req.params.keyword) .then(words => { res.render('result', console.log(words)) }); }) Here is the actual function that makes the object: function searchDictionary(searchTerm){ const url = `https://www.dictionary

Jade include with parameter

≯℡__Kan透↙ 提交于 2021-02-07 11:26:40
问题 In an older version of Jade I was able to include partials and pass variables into them like this: !=partial('partials/video', {title:video.title, artist:video.artist}) now the partial connotation does not exist any more. How do I achieve the same thing using the include connotations? 回答1: You can use mixins for that. Wrap your include content inside a mixin and call the mixin function in your pug file. See my example below. include-file.pug mixin my-include(title, description) h1= title p=

Jade include with parameter

我的梦境 提交于 2021-02-07 11:26:05
问题 In an older version of Jade I was able to include partials and pass variables into them like this: !=partial('partials/video', {title:video.title, artist:video.artist}) now the partial connotation does not exist any more. How do I achieve the same thing using the include connotations? 回答1: You can use mixins for that. Wrap your include content inside a mixin and call the mixin function in your pug file. See my example below. include-file.pug mixin my-include(title, description) h1= title p=

How to make previous and next button works in pugjs?

痞子三分冷 提交于 2021-01-29 06:31:55
问题 - var INDEX = 0; const welcomeModalData = [ { image: "welcome-modal-img-1.svg" }, { image: "welcome-modal-img-2.svg", } ] if welcomeModalData[INDEX].image != "" img.feature-img#feature-img(src=`${welcomeModalData[INDEX].image}` alt="") .welcome-modal__footer-paging button#previous-btn(type="button" onclick="onClickPreviousBtn()") Previous tip button#next-btn(type="button" onclick="onClickNextBtn()") Next tip p#pageination 1 of #{welcomeModalData.length} script. var previousBtn = document

Node JS Pass variables to pug template's JavaScript and html sections

爱⌒轻易说出口 提交于 2021-01-29 06:21:26
问题 I have the following route and it passes a serires of variables to the pug template. items.js route router.get('/edit/:itemObjectId', async function(req, res, next) { var itemObjectId = req.params.itemObjectId; var equipmentCategoryArr = []; var lifeExpectancyArr = []; var businessUnitResponsibleArr = []; var item = undefined; try { item = await db_item.getItem(itemObjectId); // Where item["result"] is either undefined or a JavaScript Object. E.g. {"createdAt":"2018-11-07T04:07:44.587Z",