给玉文件中的变量赋值 [英] assigning value to a variable inside a jade file

查看:32
本文介绍了给玉文件中的变量赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 jade 文件中分配变量,以使代码更具可读性?

Is it possible to assign variables inside a jade file, in order to make the code more readable?

具体来说,我创建了这个玉文件:

Specifically, I created this jade file:

extends layout
- var format = "%+1.0f"
block title
  title Your score table
block body
 ...
      td.utilityUtil #{sprintf(format,value)}
 ...

最后一行出现错误,未定义格式".可能我没有正确分配它,但我没有找到正确的语法.

And got an error in the last line, that "format" is not defined. Probably I don't assign it correctly, but I didn't find the correct syntax.

附言我有快递 3.

推荐答案

你必须在块范围内声明变量:

You have to declare the variable in the block scope :

extends layout
block title
title Your score table
block body
    - var format = "%+1.0f"
    ...
    td.utilityUtil #{sprintf(format,value)}
    ...

这篇关于给玉文件中的变量赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆