Cant' change variable inside conditional block

I have this code belov and when I want to append string to variable inside conditinal “if” block variable is not assigned. I also tried to do that with Scratch but scratch is not working at all inside this partial.

{{- $width := .width | default “100” -}}
{{- $height := .height | default “false” -}}
{{- $crop := .crop | default “fill” -}}
{{- $gravity := .gravity | default “north” -}}
{{- $format := .format | default “auto” -}}
{{- $quality := .quality | default “auto:good” -}}

{{- $url := “https://res.cloudinary.com/tsl/image/upload/” -}}
{{- $url := (print $url “c_” $crop “,f_” $format “,q_” $quality “,g_” $gravity) -}}
{{- $url := (print $url “,w_” $width) -}}

{{- if ne $height “false” }}
{{- $url := (print $url “,h_” .height) -}}
// This line is not changing variable at all.

{{- end -}}

{{- $url := (print $url “/” .public_id) -}}

{{- if .as_url -}}
{{ $url }}
{{- else -}}

{{- end -}}

See https://gohugo.io/functions/scratch