javascript - Pass variables to base layout from extending pug/jade template -


i set class on body tag declaring variable in template extends base layout.

when try, body_class variable undefined in layout.

it appears layout executed before extending template, or executed in different scopes or something.

is there way? mixin work here?

_layout.jade:

doctype html html(lang="en-au")     head         meta(charset="utf-8")         block css     body(class=(body_class || "it-did-not-work"))         block header         block content         block footer 

home.jade:

var body_class = 'i-am-the-home-page' extends _layout block header     h1 home 

ah ha! figured out.

create block @ top of base layout , add variables in there.

_layout.jade:

block variables doctype html html(lang="en-au")     head         meta(charset="utf-8")         block css     body(class=(body_class || "it-did-not-work"))         block header         block content         block footer 

home.jade:

extends _layout block variables     - var body_class = 'i-am-the-home-page' block header     h1 home 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -