What does “body! = Body” mean in the jade template?

This question is related to using Jade templates with Express.js .

I know that when I write layout.jade , which contains:

 !!! html body != body header h1 My header 

When I call res.render('index') , then my actual template maps to the beginning of the body .

My question is this: what does != body mean and how is Jade / Express used to determine where my template is placed inside the layout? I know that if I change != body inside another element, then the actual view is displayed instead. Does anyone know where this documentation is documented?

+6
source share
1 answer

I quote from Jade's documentation / guide:

Code buffered with = is protected by default, but you can use it to output unscreened return values! =:

p! = aVarContainingMoreHTML

When using res.render('index') displayed contents of index.jade (in your case) will be passed as a local variable to your layout file ( layout.jade ). A local variable is available as a body . However, if we simply output the local variable body , it will be escaped (special characters will be encoded). So using! =, Body content will be displayed without saving.

Check out: http://expressjs.com/guide.html#view-rendering

+7
source

Source: https://habr.com/ru/post/912759/


All Articles