pug-php/ci-pug-engine

run js code inside pug

anurat opened this issue · 3 comments

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

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('')

Hi, you can run composer update if you use PHP 7+ to get the last version of js-phpize that supports references like this.

Thanks @kylekatarnls,

After running composer update, I can use array.push() function now.