pug-php / pug

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

'Use of undefined constant' warning #106

Closed webdevian closed 7 years ago

webdevian commented 7 years ago

In a mixin I have the following line: - var selected = option.value === selectedValue where selectedValue is a mixin parameter

It compiles to the following php and throws this notice : Message: Use of undefined constant value - assumed 'value' $selected = $option['value'] === selectedValue ? true : false

I think it should compile to $selectedValue (which suppresses the notice). Unless there is a better way for me to write it?


This is the context within the mixin

mixin select(name, selectedValue, id, label, helperBelow, helperAbove, options, error)
        select(id=id, name=name)&attributes(attributes)
            each option in options
                - var selected = option.value === selectedValue
                option(value=option.value, selected=selected)= option.label
kylekatarnls commented 7 years ago

To use javascript expressions, use the option 'expressionLanguage' => 'js', else you should enter PHP expressions ($selected = $option['value'] === $selectedValue) because the default mode (auto) does just handle simple replacements if there is no possible conflict between PHP and JS syntaxes.

I will not change this behaviour since the next version comes with a complete refactoring.

webdevian commented 7 years ago

Thanks, that should make life a lot easier for me

webdevian commented 7 years ago

Slight correction, it was 'expressionLanguage' => 'js that I needed

kylekatarnls commented 7 years ago

Sorry, I edit, thanks for correction.