run js code inside pug
anurat opened this issue · 3 comments
anurat commented
Hi @kylekatarnls,
I tried to run some array manipulation code inside pug like the following.
-
var a = []
a.push(1)
a.push(2)
= a.join('')
It's supposed to output 12
but I got nothing.
What could be the problem here?
Thanks in advance,
Anurat
kylekatarnls commented
In realty, we do not run JS engine, we convert the syntax into PHP with js-phpize and it seems push lose the reference. But for now, you can use the array_push
PHP function:
-
var a = [];
array_push(a, 1)
array_push(a, 2)
= a.join('')
kylekatarnls commented
Hi, you can run composer update
if you use PHP 7+ to get the last version of js-phpize that supports references like this.
anurat commented
Thanks @kylekatarnls,
After running composer update
, I can use array.push()
function now.