Closed windware-ono closed 4 years ago
If I switch the 'engine' option in the doc to 'Pug-php' or 'Tale-pug', the demo also breaks. Am I using pug-php in the wrong way?
This example uses PHP-style expression.
Using Pug\Pug
class you're by default using JS-style expressions:
https://en.phug-lang.com/#use-javascript-expressions
For attributes, I recommend simple concatenation:
- btnType = 'info'
- btnSize = 'lg'
button(type="button" class="btn btn-" + btnType + " btn-" + btnSize)
- btn = {size: 'lg'}
button(type="button" class="btn btn-" + btn.size)
Note: ideally we should support the backtick like in Pugjs:
button(type="button" class=`btn btn-${btn.size}`)
It could be an improvement for jsphpize, but it's not yet supported.
Back-ticks and its interpolation are now supported by js-phpize:
You can run composer update
then now use:
- btnType = 'info'
- btnSize = 'lg'
button(type="button" class=`btn btn-${btnType} btn-${btnType}`)
- btn = {size: 'lg'}
button(type="button" class=`btn btn-${btn.size}`)
It can even support complex expressions, escaped characters, nested braces: https://github.com/pug-php/js-phpize/blob/master/examples/interpolation.js
Thank you! It works great.
I've tried the example in the doc but it didn't seem to work.
https://www.phug-lang.com/#attribute-interpolation
PHP (Tried 7.1 and 7.4)
composer.json
versions
test.pug
Result