using variables from layout in jade

hii i have a jade layout file. The code is as follows

html.no-js(lang='en')
  //<![end if]
  head
    script(type='text/javascript')
        var x = "datablabla";

And i have a jade file that extends this layout. How can i access that x variable??

extends ../layout

head
    script(type='text/javascript')
        alert(1);
block headerContent

block bodyContent
    h1 Wellcome to the blabla
    p #{x} // undefined

Any ideas ?

Short answer: you can't. You're declaring x in a client side script block, and Jade doesn't execute those to make any code/variables declared in such a block available within the template.

Longer answer: you can add embedded JS code in your Jade templates like this:

- var x = "datablabla";

You can reuse that x variable in both the client side part, and in your other Jade template:

// layout
- var x = "datablabla";
head
  script
    var x = '#{x}';

// other
extends layout
...
block bodyContent
  h1 Welcome to the blabla
  p #{x}