Copied to clipboard

Flag this post as spam?

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


  • Soeren Sprogoe 575 posts 259 karma points
    Jul 15, 2009 @ 13:17
    Soeren Sprogoe
    0

    Using a docs property as an HTML attribute

    Hi there,

    I'm trying to upgrade a site's template from v3 to v4, and have come across a problem that's probably pretty simple to answer.

    I'm trying to insert a documents property as a value in an HTML attribute, like this:

    <link rel="stylesheet" type="text/css" href="<umbraco:Item field="siteCustomCSS" recursive="true" runat="server"></umbraco:Item>" /> 

    But the output comes out all wrong:

    <link rel="stylesheet" type="text/css" href="&quot;&lt;umbraco:Item" field="siteCustomCSS" recursive="true" /></umbraco:Item>" />

    How do I fix this? What am I doing wrong here?

    Best regards,
    Soeren S.

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 15, 2009 @ 13:21
    Ismail Mayat
    1

    try

    changing

    href="<umbraco:Item field="siteCustomCSS" recursive="true" runat="server"></umbraco:Item>" /> 

     

    to

    href="<umbraco:Item field='siteCustomCSS' recursive='true' runat='server'></umbraco:Item>" /> 
  • Soeren Sprogoe 575 posts 259 karma points
    Jul 15, 2009 @ 13:37
    Soeren Sprogoe
    0

    Nope, no luck. It still comes out all wrong :-/

    /SoerenS

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 15, 2009 @ 13:43
    Jan Skovgaard
    0

    Would it be a possibility for you to make it as an xslt macro instead?

    I am quite sure that it should be possible to have an XSLT macro inserted into the href attribute and getting the correct value.

    /Jan

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2009 @ 13:44
    Warren Buckley
    0

    OK try this single quotes for the item in the double quotes, should hopefully fix it.

    <link rel="stylesheet" type="text/css" href="<umbraco:Item field='siteCustomCSS' recursive='true' runat='server'></umbraco:Item>" />

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2009 @ 13:45
    Warren Buckley
    0

    Sorry just seen that Ismail suggested that, but what is the ouput when you do it with single quotes?

  • Soeren Sprogoe 575 posts 259 karma points
    Jul 15, 2009 @ 13:50
    Soeren Sprogoe
    0

    Close to being the same:

    <link rel="stylesheet" type="text/css" href="&lt;umbraco:Item field='siteCustomCSS' recursive='true' runat='server' />" />

    Not sure why it keeps insisting on writing &lt;

    When I copy the stuff outside of the HTML attribute it works just fine.

    @Jan: Yeah, when I give up that'll be the solution. It just bothers me why I can't figure out getting something as simple as this to work...

    /SoerenS

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 15, 2009 @ 13:53
    Jan Skovgaard
    0

    Strike my suggestion - does'nt work in v4...

    But I guess the solution would be to make a macro in, which you write something like this

     

    <xsl:variable name="css">
    <xsl:value-of select="$currentPage/ancestor-or-self::node/data[@alias='stylesheet']" />
    </xsl:variable>

    <link rel="stylesheet" type="text/css" href="{$css}" />

    /Jan

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2009 @ 13:55
    Warren Buckley
    0

    I am not sure why it would be rendering it like that as when you insert an umbraco:item into a src attribute of an <img> tag it works just fine.

    Can I ask why you have a field to store a path to a customCSS file, as maybe this could be implemented easier to avoid this problem?!

    Warren

  • Soeren Sprogoe 575 posts 259 karma points
    Jul 15, 2009 @ 13:55
    Soeren Sprogoe
    2

    Hah, found it!

    I've been using the default Runway site template, that starts out with:

    <head id="head" runat="server">

    Seems like when you tell an element to be run server side you'll have problems with macros.

    Thanks for trying to help guys!

    /SoerenS

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 15, 2009 @ 13:56
    Jan Skovgaard
    0

    I think the reason why this is not working could maybe be because of the new template system, which as you surely know is based entirely on the .NET masterpages.

    And I don't think you are allowed to assign values to attributes like we could do in earlier versions than v4. But I am not quite sure. Just a thought since my first suggestion does not work either.

    Maybe some .NET experts can clear this one out?

    /Jan

  • Soeren Sprogoe 575 posts 259 karma points
    Jul 15, 2009 @ 13:57
    Soeren Sprogoe
    0

    @Warren: It's for a solution that is running multiple similar sites. Each is using the same template system, but has a single, simple custom CSS that changes site logo, colors and simple stuff like that.

    /SoerenS

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 15, 2009 @ 13:59
    Dirk De Grave
    3

    Yep, runat="server" is the culprit; Richard has done a blogpost on that...

  • Soeren Sprogoe 575 posts 259 karma points
    Jul 15, 2009 @ 14:02
    Soeren Sprogoe
    0

    @Dirk: Ah, I knew I've read about the problem somewhere! That's why it was extra super annoying that I couldn't find a solution right away :-P

    Thanks for all the help!

    /SoerenS

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2009 @ 14:04
    Warren Buckley
    0

    Glad you got it solved - if only you could mark your own post as the solution !

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jul 15, 2009 @ 14:05
    Warren Buckley
    0

    Glad you got it solved - if only you could mark your own post as the solution !

  • Masood Afzal 176 posts 522 karma points
    Jul 15, 2009 @ 14:53
    Masood Afzal
    2

    this works fine, change it to meet your requirements

    <umbraco:Item ID="m_metaKeywords" Field="metaKeywords" runat="server" Xslt="concat('<meta name=&quot;keywords&quot; content=&quot;',{0},'&quot;/>')" XsltDisableEscaping="true"  recursive="true"></umbraco:Item>

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 15, 2009 @ 15:08
    Lee Kelleher
    0

    Glad removing the runat="server" attribute sorted the problem.

    On a side note, here is what I usually do instead of including <umbraco:Item> tags in attributes - I use the "insertTextBefore" and "insertTextAfter" properties.

    <umbraco:Item field="siteCustomCSS" recursive="true" insertTextBefore="&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;" insertTextAfter="&quot; media=&quot;screen&quot; /&gt;" runat="server"></umbraco:Item>

    This way if the "siteCustomCSS" property has no value, the rest of the <link /> tag will not be rendered.

Please Sign in or register to post replies

Write your reply to:

Draft