0

我正在尝试将title变量传递到文件的head部分_layout.pug。我看不出有什么方法可以巧妙地实现这一点,所以不得不求助于块中的预置变量:

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

prepend headStuff
    -var title = 'The Positioning Schema'

我以错误的方式攻击这个吗?这应该是一个mixin吗?

4

1 回答 1

0

通常,像标题这样的东西会作为变量从它连接到的任何后端(节点,通常对我来说)传递。但是,如果您只是使用它直接编译为没有后端的静态 HTML,那么您应该能够将其传递给block head

布局.pug

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

主程序

extends layout
block head
  title The main page

block content
  h1 This is the main page content
  p And more of it.
于 2017-12-12T17:48:39.147 回答