var title = string.IsNullOrWhiteSpace(item.Title) ? item.Name : item.Title;
<li><a href="@item.Url">@title</a>
}
</ul>
Fairly simple. Still, this is giving me a parser error:
The foreach block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
I don't understand why this error comes up. The { and } are clearly balanced, there's no bracket that's unmatched.
(unrelated: markdown doesn't seem to be working?)
(edit: code looks better now... a little weird to highlight every line, tho... I'm new here so I don't know if code is supposed to look that way)
I'm using HTML5, so </li> is optional, and in practice absolutely never needed for anything. There's no reason to have it. Same goes for a bunch of other closing tags.
In fact, this may seem scary at first, but all closing tags within a <table> are optional, and no valid code ever requires them. The <head> is optional, too, and so is <body> and even <html> (the tags that is, not the contents within).
...which is why I shouldn't be required to use them.
Martin while you dont strictly have to close tags. You should do. For instance where you have <li> not closed. You would not be able to open another <li>
Some closing tags are optional, however. The tags are optional because it’s implied that a new tag would not be able to be started without closing it. These are the following: html, head, body, p, dt, dd, li, option, thead, th, tbody, tr, td, tfoot, colgroup. There are also tags that are forbidden to be closed: img, input, br, hr, meta, etc.
It's been a while since I worked at this project, but I am now, so I noticed this topic I created...
@Charles, you are wrong. Your quote is right though. The </li> tag is optional, always. If you open a new <li> without having closed the previous one, a closing tag will be implied. Every browser that has ever been released works this way. The standard just describes that fact.
So the template engine should not require me to write something that is completely optional, and absolutely never needed in any situation ever, at all.
I don't see why I should close these tags explicitly. It doesn't do anything.
Unfortunately the template engine isn't clever enough to differentiate between those tags that need to be closed and those that don't. So it treats everything as a tag that needs to be closed, hence the error you see. It's a limitation of the ASP.NET MVC Razor template engine, not something that can be fixed for Umbraco. That being said, you can work around it by rendering the <li> tag as content, eg. replace <li><a href="@item.Url">@title</a> with @Html.Raw("<li>")<a href="@item.Url">@title</a> - that should keep the parser happy.
Parser error - can't see why
Here's my code:
Fairly simple. Still, this is giving me a parser error:
The foreach block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
I don't understand why this error comes up. The { and } are clearly balanced, there's no bracket that's unmatched.
(unrelated: markdown doesn't seem to be working?)
(edit: code looks better now... a little weird to highlight every line, tho... I'm new here so I don't know if code is supposed to look that way)
@{
foreach(var item in items)
{
var title = string.IsNullOrWhiteSpace(item.Title) ? item.Name : item.Title;
<li>
<a href="@item.Url">@title</a>
</li> // you missed <li> closing tag
}
}
I'm using HTML5, so
</li>
is optional, and in practice absolutely never needed for anything. There's no reason to have it. Same goes for a bunch of other closing tags.In fact, this may seem scary at first, but all closing tags within a
<table>
are optional, and no valid code ever requires them. The<head>
is optional, too, and so is<body>
and even<html>
(the tags that is, not the contents within)....which is why I shouldn't be required to use them.
Martin while you dont strictly have to close tags. You should do. For instance where you have <li> not closed. You would not be able to open another <li>
Some closing tags are optional, however. The tags are optional because it’s implied that a new tag would not be able to be started without closing it. These are the following:
html, head, body, p, dt, dd, li, option, thead, th, tbody, tr, td, tfoot, colgroup
. There are also tags that are forbidden to be closed:img, input, br, hr, meta, etc.
Charlie
It's been a while since I worked at this project, but I am now, so I noticed this topic I created...
@Charles, you are wrong. Your quote is right though. The
</li>
tag is optional, always. If you open a new<li>
without having closed the previous one, a closing tag will be implied. Every browser that has ever been released works this way. The standard just describes that fact.So the template engine should not require me to write something that is completely optional, and absolutely never needed in any situation ever, at all.
I don't see why I should close these tags explicitly. It doesn't do anything.
Unfortunately the template engine isn't clever enough to differentiate between those tags that need to be closed and those that don't. So it treats everything as a tag that needs to be closed, hence the error you see. It's a limitation of the ASP.NET MVC Razor template engine, not something that can be fixed for Umbraco. That being said, you can work around it by rendering the <li> tag as content, eg. replace <li><a href="@item.Url">@title</a> with @Html.Raw("<li>")<a href="@item.Url">@title</a> - that should keep the parser happy.
Stephan
is working on a reply...