The @ symbol is used in Razor initiate code, and tell the compiler where to start interpreting code, instead of just return the contents of the file as text. Using a single character for this separation, results in cleaner, compact code which is easier to read.
The reason you experience that you if statement is just being outputted as plain text is because you have HTML markup in your code,
and now you are out of razor. Therefor you need to to start the razor eigne again and tell the compiler where to start interpreting code by using the @ sign.
It looks like your nested if statements are being interpreted as plain text because they are contained within HTML Markup, try prefixing your if with an @ symbol, for example:
Nested If statements
Umbraco 6
I noticed something that seems strange.... Within my partial view, I have a nested if statement:
When rendered in a web page, the following text kept getting printed out to the page:
Then I put an '@' in front of that if statement, and now it's working like I expect.
I thought that once I'm inside of a code block starting with:
...that I don't have to preprend if statements with '@'
Note that within the larger code block, I have other if statements that appear to be working just fine, without any preceding 'a':
What am I not understanding?
Hi Jacob,
The @ symbol is used in Razor initiate code, and tell the compiler where to start interpreting code, instead of just return the contents of the file as text. Using a single character for this separation, results in cleaner, compact code which is easier to read.
http://our.umbraco.org/documentation/Reference/Templating/Macros/Razor/basic-razor-syntax
The reason you experience that you if statement is just being outputted as plain text is because you have HTML markup in your code,
Just like when you outputted your h3 heading.
I hope this explanation why you need the @ is more clear to you now.
/Dennis
Good Morning Jacob,
It looks like your nested if statements are being interpreted as plain text because they are contained within HTML Markup, try prefixing your if with an @ symbol, for example:
Let me know if you have anymore issues.
Thanks,
Sam
Thanks Dennis for the reference and Sam for your comment. I was making assumptions about the compiler. I understand now.
is working on a reply...