pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Interpolation break on attributes #157

Closed SebastianGrzymala closed 7 years ago

SebastianGrzymala commented 7 years ago

This code doesn't work:

[ 'host' => 'http://www.abc.com/', 'filename' =>'def.jpg' ]

a(href=host + filename) Link

https://pug-demo.herokuapp.com/ script returns:

<a href="0">Link</a>

Should be:

a(href="http://www.abc.com/def.jpg") Link

Pug node returns as above

SebastianGrzymala commented 7 years ago

I fixed it using this code: a(href=''+host + filename) Link

kylekatarnls commented 7 years ago

You should be in the default expressionLanguage mode (auto), and indeed, in this mode, your only way to be sure to have a string concatenation is to start with a empty string because the auto mode try to guess if your expressions are in PHP or JS.

But you can also choose the PHP mode and write all your expressions in PHP:

$pug = new Pug(array('expressionLanguage' => 'php'));
echo $pug->render('a(href=$host . $filename) Link', array(
    'host' => 'http://www.abc.com/',
    'filename' =>'def.jpg'
));

Or choose the JS mode and so you will be able to use JS expression with a better support:

$pug = new Pug(array('expressionLanguage' => 'js'));
echo $pug->render('a(href=host + filename) Link', array(
    'host' => 'http://www.abc.com/',
    'filename' =>'def.jpg'
));

Feel free to re-open if you have more questions about it.

SebastianGrzymala commented 7 years ago

Thank you.