pug-php / pug

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

Conditional with two variable #127

Closed NekoOs closed 7 years ago

NekoOs commented 7 years ago

Content into index.php

$pug = new Pug(array(
    'extension' => '.pug'
));
$pug->render('vista.pug', [
    'variable1' => 150,
    'variable2' => 150
]);

Content into vista.pug

if (variable1 == variable2)
      a exito
 else
      a fracaso
response: Notice: Use of undefined constant dos - assumed 'dos'

Error case

if (variable1 == "#{variable2}")
      a exito
 else
      a fracaso
response: fracaso
if (variable1 == !{variable2})
      a exito
 else
      a fracaso
response: fracaso

Succefull case

if (variable1 == "150")
      a exito
 else
      a fracaso
response: exito
if ($variable1 == $variable2)
      a exito
 else
      a fracaso
response: exito

How can I make a comparison of variables without using php variables.

PD: Sorry the semantics but I do not speak English

kylekatarnls commented 7 years ago

Hi, your first code can work with js option: "expressionLanguage" => "js" added on the Pug constructor array. The codes on your paragraph Error cases are not supposed to work neither in the last version of Pugjs nor in pug-php. Else parentheses are not necessary and if statements can contain PHP code.

Cantuares commented 7 years ago

Thanks @kylekatarnls!