[Jade] Use Mixins in Pug

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Jade] Use Mixins in Pug相关的知识,希望对你有一定的参考价值。

Mixin works as a function.

extends layout

include mixins/storeForm

block content
    .inner
        h2 #{title}
        +storeForm({name: ‘NODE‘})

Here, we use include keyword to inlcude a mixin file.

include mixins/storeForm

 

Exec a mixin function we can use ‘+‘:

+storeForm({name: ‘NODE‘})

 

Define a mixin:

mixin storeForm(store = {})
    form(action="/add" method="POST" class="card")
        label(for="name") Name
        input(type="text" name="name")
        label(for="description") Description
        textarea(name="description")
        - const choices = [‘Wifi‘, ‘Open Late‘, ‘Fmaily Friendly‘, ‘Vegatarian‘, ‘Licensed‘];
        ul.tags
            each choice in choices
                .tag.tag__choice
                    input(type="checkbox" id=choice value=choice name="tags")
                    label(for=choice) #{choice}
        input(type="submit" value="Save" class="button")

Here we use some js code:

- const choices = [‘Wifi‘, ‘Open Late‘, ‘Fmaily Friendly‘, ‘Vegatarian‘, ‘Licensed‘];

to hard code some categories.

以上是关于[Jade] Use Mixins in Pug的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Jade / Pug 呈现内联 JavaScript?

在 Jade(目前称为“Pug”)模板引擎中循环

Pug (Jade) 动态添加属性内联的存在

pug模板引擎(原jade)

我最喜欢的模板jade(pug)学习和使用

使用 webexpress 和 pug/jade 通过 Autodesk forge 查看器提供页面