I found some solutions that depend on the form of development in which it is being applied:
Solution 1: Using a if else
conditioner to check whether or not the element exists:
html
head
title= Testando
body
if (bar && bin)
bar bin
else if (bar && !bin)
bar world!!!
This solution is interesting when you have to import a file or a mixed-code block between variables and content .
Solution 2: Using tenant operators for field validation:
html
head
title= Testando
body
typeof bin == 'undefined' ? bar world!!! : bar bin
Working with tenant operators, you will always have a callback for that parameter .
Solution 3: declare these variables with the Unbuffered Code :
- var bin = bin || 'world!!!';
- var bar = bar || 'hello ';
html
head
title= Testando
body
bar bin
I noticed that I can change the value of the variables depending on the file to be imported, that is, if there is a new declaration - var bin = bin || 'foo!!!';
* I can change the default value of the content that should be displayed or of the expression bin will be declared as * - var bin = '123'
.
Solution 4: declare these variables with the Buffered Code a> :
html
head
title= Testando
body= (bar || 'hello ') + (bin || 'world!!!')
This solution is an implementation of Solution 2 without variant declaration. The Pug understands that content of the type document.body.innerHTML (which is the tag in question) will be populated with the result of the expression.
Solution 5: Declare these variables with the Unescaped Buffered Code :
html
head
title= Testando
body
!= (bar || 'hello ') + (bin || 'world!!!')
This solution, which I see as more satisfying, allows that anywhere, regardless of whether I am inside a block of content, I can insert a complete expression, so I do not depend on a .