Hi Paolo, Roberto,
Thank you very much.
Paolo,
Your response helped me with the issue. Your option A) worked very
well!!. Thanks again... However your option B) gave incorrect result. Your
That is, it is thinking of the statement as follows:
if ... :
if ..... :
else:
....
But what i intend to do is the following:
if ....:
if......:
.....
else:
....
It gets very difficult to apply the if.. else statements in more complex
situations inside the view html code if the basics are not clearly
understood. So i really want to understand the exact new syntax of using
the if... else... in view html files before i start using them more and
more.... Your help is greatly appreciated.
--Regards,
Bhaskar
On Monday, December 24, 2012 5:58:47 PM UTC-6, Paolo Caruccio wrote:
>
> "else:" statement is inline with "if" statement.
> the code wrapped in {{ }} follows python syntax rules.
>
> Alternatives below should work (not tested):
>
> A) using ternary operator
> <a href="#"><i class="{{if ans=='A': }} {{response.write('icon-ok') if
> ans==correctans else response.write('icon-remove')}} {{ pass }}"></i></a>
>
> B) inline syntax with multiple {{ }}
> <a href="#"><i class="{{if ans=='A': }} {{if ans==correctans:
> response.write('icon-ok')}} {{else: response.write('icon-remove')}}
> {{pass}} {{ pass }}"></i></a>
>
> C) syntax not in line
>
> <a href="#"><i class="{{if ans=='A': }}
> {{if ans==correctans: response.write('icon-ok')
> else: response.write('icon-remove')
> pass }}
> {{ pass }}"></i></a>
>
>
>
> Il giorno martedì 25 dicembre 2012 00:40:01 UTC+1, Bhaskar Ramachandran ha
> scritto:
>>
>> <a href="#"><i class="{{if ans=='A': }} {{if ans==correctans:
>> response.write('icon-ok') else: response.write('icon-remove') pass }} {{
>> pass }}"></i></a>
>>
>> I get a syntax error for the above code in view html file. I am trying to
>> dynamically insert a tick icon or a cross icon depending on some variables.
>> I tried different ways of expressing the if statements and none of them
>> worked. I followed the book that says we should introduce a pass statement
>> for every block (sometimes the block is obvious and in that case we don't
>> need a pass statement).
>>
>> Please help catch the cause for syntax error.. Thank you
>>
>>
--