简体   繁体   English

将参数传递给Jade / Pug模板

[英]Pass arguments to Jade/Pug templates

I'm trying to pass the title variable into the head section of the _layout.pug file. 我正在尝试将title变量传递到_layout.pug文件的head i can't see any way to achieve this neatly so have had to resort to pre-pending variables to the block: 我看不到任何方法可以巧妙地实现这一目标,因此不得不求助于将变量预先添加到块中:

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

prepend headStuff
    -var title = 'The Positioning Schema'

Am I attacking this the wrong way? 我是用错误的方式攻击吗? Should this be a mixin? 这应该是mixin吗?

Normally, things like the title would be passed through as variables from whatever back end it's hooked up to (node, usually for me). 通常,诸如标题之类的东西将从其所连接的任何后端(节点,通常对我而言)作为变量传递。 If you're just using it to compile straight to static HTML without a back end, though, you should just be able to pass it to the layout in block head 如果你只是用它来直接编译成静态的HTML没有后端,但是,你应该只能够给它传递给布局block head

layout.pug layout.pug

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

main.pug 主.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