Alex Rivera | Logout

assigning value to a variable inside a jade file

Asked 2012-12-23T11:47:56.573
19

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.

pug
Edit
Report

1 Answer

24

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)}
    ...
answered 2013-01-04T11:00:57.597

Your Answer