I am having a variable scope issue in Jinja that is misaligning a table. I am trying to convert the current template that is written in Cheetah to Jinja but for some reason this block of logic does not translate and getting the output the python is an even bigger mess.
Original cheetah code
#set $sname = ""
#for $serv in $proc:
#if $serv.id == $v[8]:
<td> $serv.shortname </td>
#set $sname = $serv.shortname
#end if
#end for
#if $sname == "":
<td><span style="color:#ff0000">Server not found</span></td>
#end if
So the desired output of the code above is loop through some objects match the ids to the current row object and update the value. then check if the value is still null and print no server found instead.
Jinja Code that doesnt work
{% set sname = "" %}
{{ v[8] }}
{% for serv in proc %}
{% if serv.id == v[8] %}
<td> {{ serv.shortname }} </td>
{% set sname = serv.shortname %}
{% endif %}
{% endfor %}
{% if sname == "" %}
<td><span style="color:#ff0000">Server not found</span></td>
{% endif %}
This code instead if it correctly matches the ids it prints both columns because outside of the loop the sname is still set to "". I tried doing the comparison inside the loop but it printed something like
Server Not found | ServerName | Server not found