Open cronfy opened 7 years ago
It's not possible to disable them completely right now, but you can control them with ?
. Writing ?#{$var}
will disable it for that interpolation.
http://sandbox.jade.talesoft.codes/id-5853e8edde434.html
It seems I completely forgot about isset checks when using Variable-tokens.
You can avoid this by prepending =
Take a look at this:
http://sandbox.jade.talesoft.codes/id-5853e9c11d62a.html
I will not patch this in Tale Jade, as we're currently discussing the automatic isset()
checks for our new Phug implementation and we will implement a consistent behavior over there.
Thanks for advices! I hope in Phug isset checks will be configurable :) BTW, when are you going to release it?
We don't know yet, we basically just started and we're working out the structure and guidelines currently. A lot of stuff has already been finished. This time we aim to become one of the bigger, professional template engines ready for production and enterprise usage. Because of this, we take our time, make sure to find stable and convenient structures and write docs and unit tests without an end to them.
Once it's usable, Tale Jade will fade into the background in favor of Phug. There will be extensions that mimic Tale Jade behavior, so you don't have to change a thing in your existing templates (Most of Tale Jade's "Special-Features" will be put into extensions)
Sounds great! Have a luck with it!
Could you please give a hint where I can disable isset checks for myself in Tale-jade source?
My friend, you won't like the answer. The isset checks are implemented very deeply.
https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L762 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L1559 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L1602 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L1664 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L1694 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L1727 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L1857 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L2056 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L2219 https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L2288
The only thing you could try to avoid editing the whole compiler is (maybe) changing Compiler->isVariable()
to return false
all the time. It's what I use to check if isset should be wrapped or not.
https://github.com/Talesoft/tale-jade/blob/master/Compiler.php#L674
Keep in mind that this could break other things, I remember I also used that somewhere in mixin argument checks and stuff.
I wrote Tale Jade with these isset-checks in mind, since I was porting JavaScript templates to PHP and PugJS does something similar with undefined variables. When I was porting I ran into constant E_NOTICE
-floods because this, that and these are not defined.
Why do you want to disable them completely?
Thanks a lot, I'll give it a try!
I prefer to eliminate "undefined variable" errors instead of hiding them. I
use Yii2, where any undefined variable throws an exception. I also use
Twig, it has strict_variables
option, which does the same, and I keep it
always enabled.
Anyway, I think that whether to ignore undefined variables or not is a matter of project coding guidelines/taste and should be configurable for template engine.
Consider this code:
Produces:
First occurence was checked by isset, and second was not.