Copied to clipboard

Flag this post as spam?

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


  • Peter Duncanson 430 posts 1360 karma points c-trib
    Apr 05, 2010 @ 20:20
    Peter Duncanson
    0

    umbraco:Items can't be the value for an HTML id field

    I want to simply render out a different id on my body tag depending on the page.

    <body id="something">

    But its not easy, I'm guessing this is due to a .net limitation but I've noticed that you can't do this:

    <body id="<umbraco:Item field="Page.BodyTagID" stripParagraph="true" runat="server" />">

    as it caused this error:

    Parser Error Message: '"<umbraco:Item' is not a valid identifier.

    Instead you have do this using before and after text attributes:

    <body<umbraco:Item field="Page.BodyTagID" insertTextBefore=" id=&quot;" insertTextAfter="&quot;" stripParagraph="true" runat="server" />

    which is a shame as its longer, harder to read and just a bit of a pain in the ass. But it works. An advantage to this way though is you save 6 bytes being sent down the wire if no id is needed but...

    Any alternatives or fixes anyone knows of?

    After reading the "tips on using XSL" which showed you can use Entities I thought that might be a nice way around it but equally I don't think its a good idea to go around polluting your entities list all the time as its not a straight forward technique so hinders debugging, still might work nicely this is instance.

     

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 05, 2010 @ 20:30
    Sebastiaan Janssen
    1

    Well you could always do it with single quotes, much easier on the eyes:

    <body id='<umbraco:Item field="Page.BodyTagID" stripParagraph="true" runat="server" />'>

     

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Apr 05, 2010 @ 21:17
    Peter Duncanson
    0

    But not valid HTML :(

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 05, 2010 @ 21:19
    Jan Skovgaard
    1

    Hi Peter

    Try what Sebastian is suggesting and you'll see that the output generated is perfectly valid allthough the code looks rather ugly.

    /Jan

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 05, 2010 @ 21:53
    Sebastiaan Janssen
    0

    Yes, the W3 validator doesn't care whether you use single our double quotes! Just keep the start and end quote style the same and you're good to go.

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Apr 05, 2010 @ 22:40
    Peter Duncanson
    2

    Ok so it works, but my built in validator in my head does not like it :)

    Still with a little juggling of the quote I got it to work using singles for the umbraco tag and doubles around the attribute, win win.

    <body id="<umbraco:Item field='Page.BodyTagID' stripParagraph='true' runat='server' />">

    Thanks guys.

Please Sign in or register to post replies

Write your reply to:

Draft