Closed char101 closed 4 years ago
Hello, ??
does not exist in JS.
As your expression is in JS-style, you should use:
p #{ a || 'a' }
Or to match exactly the behavior of ??
:
p #{ a === null ? 'a' : 10 }
Else in PHP-style:
p #{ $a ?? 'a' }
Thanks.
Hi, thanks for the prompt answer. Since #{ a }
works I was assuming it was php style expression without $
prefix for variables (ala Twig) but apparently it was the library doing magic tricks 😁 .
What exactly happens is a ?? 'a'
failed to be parsed as a JS expression so it's evaluated as is by PHP but a
constant does not exist, that's why other expression above work.
Note: I discovered the meaning of "ala" here https://www.yourdictionary.com/ala For the side story, I'm French and "ala" does not exist in French, we would say "à la Twig" as a familiar short-hand for "à la manière de Twig" the definition given by this dictionary is right for "prepared in a certain way" ("à la" may match this part of the definition), but as for "or for a particular" and the "chicken ala king" example, that definitely does not come from the French language. ^^
Thanks for the explanation. I wasn't familiar yet with the ecosystem for the library. So pug-php
by default renders expression using js style with js-phpize
.
As a side note, I am Indonesian, and in this language, ala means exactly like a la in French, which is in the style of, which is why I confuse the two 😁 .
Hello,
With the variables set as
['a' => 10]
I encountered an issue with the following code:
I expected to get:
But I actually get:
Thanks!