Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assigning value to a variable inside a jade file

Tags:

pug

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.

P.S. I have Express 3.

like image 932
Erel Segal-Halevi Avatar asked Dec 23 '12 11:12

Erel Segal-Halevi


1 Answers

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)}
    ...
like image 137
Guy Avatar answered Nov 16 '22 23:11

Guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!