Copied to clipboard

Flag this post as spam?

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


  • David Park 32 posts 52 karma points
    Feb 15, 2011 @ 13:36
    David Park
    0

    Image tag in a macro - rookie question!

    Hi folks,

    I have a bit of a rookie issue. I am using a macro to list elements of subpages on a parent page, and one of the things I pull through is an image via an upload tool on the child pages.

    On the child template I have my syntax like this:

    <img src='<umbraco:Item field="offerImage" runat="server"></umbraco:Item>' />

    which renders the image.

    But on the macro itself, I can only render the image URL using this:

    <xsl:value-of select="data [@alias = 'offerImage']" disable-output-escaping="yes"/>

    I essentially want to do this on my macro to render the image as opposed to simply the URL:

    <img src='<xsl:value-of select="data [@alias = 'offerImage']" disable-output-escaping="yes"/>' />

    but there is an error flagged up when I wrap the xsl:value-of in an img tag.

     

    Can anyone help me with the syntax required on the macro to essentially achieve this:

    <img src='<xsl:value-of select="data [@alias = 'offerImage']" disable-output-escaping="yes"/>' />

     

    Thanks in advance!

     

  • kows 81 posts 151 karma points c-trib
    Feb 15, 2011 @ 13:42
    kows
    0

    <img>
        <xsl:attribute name="src">
          <xsl:value-of select="data [@alias = 'offerImage']" disable-output-escaping="yes"/>
        </xsl:attribute>
    </img>

     

    ?

  • David Park 32 posts 52 karma points
    Feb 15, 2011 @ 13:59
    David Park
    0

    Ooooooooooooooh you legend!

    Thanks a lot for that, easiest karma you'll ever earn!

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Feb 15, 2011 @ 14:04
    Douglas Robar
    0

    As a shorter alternative that does the same thing...

    <img src="{data [@alias='offerImage']}" />

    Notice the use of inline expansion with the { }. Basically, whatever you'd put in the select="" xpath of an xsl:value-of can go inside { }... but you can only use the { } inside a tag's attribute. But since that's what you're doing here it works a treat.

    There shouldn't be anything that would require escaping in the offerImage property since it is just a path and filename.

    cheers,
    doug.

  • David Park 32 posts 52 karma points
    Feb 15, 2011 @ 14:13
    David Park
    0

    Thanks very much for the elaboration. It's helps in understanding the syntax and logic.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies