Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Martijn 10 posts 29 karma points
    May 07, 2014 @ 13:45
    Martijn
    0

    Parser error - can't see why

    Here's my code:

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "umbLayout.cshtml";
        var items = CurrentPage.Children();
    }

    <ul>
      @foreach (var item in items) {
        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)

  • Benas Brazdziunas 34 posts 155 karma points c-trib
    May 30, 2014 @ 11:31
    Benas Brazdziunas
    0

    @{
        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
        }
    }

  • Martijn 10 posts 29 karma points
    Jul 02, 2014 @ 16:27
    Martijn
    0

    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.

  • Charles Afford 1163 posts 1709 karma points
    Jul 08, 2014 @ 14:07
    Charles Afford
    0

    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

  • Martijn 10 posts 29 karma points
    Mar 05, 2015 @ 14:43
    Martijn
    0

    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.

  • Stephen 767 posts 2273 karma points c-trib
    Mar 05, 2015 @ 16:21
    Stephen
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft