繁体   English   中英

将参数传递给Jade / Pug模板

[英]Pass arguments to Jade/Pug templates

我正在尝试将title变量传递到_layout.pug文件的head 我看不到任何方法可以巧妙地实现这一目标,因此不得不求助于将变量预先添加到块中:

//- _layout.pug
html
    head
        block headStuff
            title #{title}
//- main.pug
extends _layout

prepend headStuff
    -var title = 'The Positioning Schema'

我是用错误的方式攻击吗? 这应该是mixin吗?

通常,诸如标题之类的东西将从其所连接的任何后端(节点,通常对我而言)作为变量传递。 如果你只是用它来直接编译成静态的HTML没有后端,但是,你应该只能够给它传递给布局block head

layout.pug

html
  head
    //standard head stuff that applies to all pages
    block head
  body
    //generic layout stuff
    block content

主.pug

extends layout
block head
  title The main page

block content
  h1 This is the main page content
  p And more of it.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM