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
Post a Comment