pug - Changing a variable inside a if - jade/pugjs -


i'm trying make div have location inside of based on state of 2 variables, example if $city = 'new york' , $state = 'ny' div display new york, ny. however, it's not working , think has scoping. here's jade:

$city = data.city $state = data.state $locstring = ""  if $city != ""     $locstring = $locstring + $city if $city != "" && $state != ""     $locstring = $locstring + ", " if $state != ""     $locstring = $locstring + $state  .location #{$locstring} 

this ending $locstring being empty, if print off $locstring inside if statements has added value, suggesting redeclaring local copy of variable inside of each if statement. can't find in reference http://jade-lang.com/reference/

i woud suggest this:

- var city = data.city - var state = data.state - var locstring = ""  if city != ""     - locstring = locstring + city if city != "" && state != ""     - locstring = locstring + ", " if state != ""     - locstring = locstring + state 

take care of "var" , "-".

check "variables" part on -> https://naltatis.github.io/jade-syntax-docs/


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -