I have found some solutions that depend on the form of development in which it is being applied:
Solution 1: Using a conditioner if else
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 import a file or a mixed code block between variables and content.
Solution 2: Using tennis operators for field validation:
html
head
title= Testando
body
typeof bin == 'undefined' ? bar world!!! : bar bin
Working with tennis operators, you will always have a callback for that parameter.
Solution 3: declare these variables with the resource Unbuffered Code:
- var bin = bin || 'world!!!';
- var bar = bar || 'hello ';
html
head
title= Testando
body
bar bin
I realized that so I can change the value of the variables depending on the file to be imported, ie if there is a new declaration - var bin = bin || 'foo!!!';
*I can change the default value of the contents that should be shown or the expression that bin will be declared as in * - var bin = '123'
.
Solution 4: declare these variables with the resource Buffered Code:
html
head
title= Testando
body= (bar || 'hello ') + (bin || 'world!!!')
This solution is an implementation of Solution 2 without declaring variants. Pug understands that the content of type Document.body.innerHTML (which is the tag in question) will be completed with the result of the expression.
Solution 5: declare these variables with the resource Unescaped Buffered Code:
html
head
title= Testando
body
!= (bar || 'hello ') + (bin || 'world!!!')
This solution, which I see as more satisfactory, allows me to insert a complete expression anywhere, regardless of whether I’m inside a content block, so I don’t depend on a tag.
I didn’t quite understand what the syntax for default values is... you say it’s the same commented code
//'bin': 'world!!!'
? You can merge objects and the initial object has the default value, which will be overwritten if there is another.– Sergio