Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Sep 04, 2013 @ 14:36
    Paul Griffiths
    0

    Help with get media xslt

    Hey guys im wondering if anyone can point me in the right direction please. Im a novice so appologies if im asking an obvious question here. Ive been working on displaying an image using the media picker and thanks to Lee Kellehers great code snippet found here ive been able to render what I want. However, im trying to display a title when the user hovers over the image but i cant get it to work. Ideally i would like to selcect the value from a property in the doc type but I cant even get the @nodeName to display. Ive tried creating variables similar to how i have created the ones below to set the width and height and ive also tried using <xsl:attribute name="title"><xsl:value-of select="@nodeName"/></xsl:attribute> but Im still not having any luck. I would like to also select the link value from the doc type so once i get the answer it will be the same i should imagine. Id be really gratefull if someone could point me in the right direction, im struggling here.

    My XSLT snippit

    <xsl:param name="currentPage"/>
        <xsl:variable name="advertismentImage" select="number($currentPage/advertismentImage)" />
        <xsl:variable name="imageWidth" select="number(329)" />
        <xsl:variable name="imageHeight" select="number(265)" />

    <xsl:template match="/">
       
        <xsl:if test="$advertismentImage > 0">
            <xsl:variable name="media" select="umbraco.library:GetMedia($advertismentImage, 0)" />
            <xsl:if test="$media/umbracoFile">
               
                <a href="{umbracoFile}" class="lightbox">
                <img src="{$media/umbracoFile}" height="{$imageHeight}" width="{$imageWidth}"/>
                </a>
                </xsl:if>
        </xsl:if>
    </xsl:template>

    Thanks

    Paul

  • Dan 1288 posts 3921 karma points c-trib
    Sep 04, 2013 @ 14:43
    Dan
    100

    Hi Paul,

    It really depends where the title for the image is coming from. Sometimes you'd have it in your content (i.e. as a property in the document type) or sometimes you might have it as a property on your media type.

    If the former, so if there's a property on the document type with the alias 'imageTitle' then you could do this:

    <img src="{$media/umbracoFile}" height="{$imageHeight}" width="{$imageWidth}" title="{$currentPage/imageTitle}" />
    

    If the title is coming from the media item though you'd do this:

    <img src="{$media/umbracoFile}" height="{$imageHeight}" width="{$imageWidth}" title="{$media/imageTitle}" />
    

    There are ways to neaten this up but it depends where in the mark-up you need the title setting - obviously here it's just going to appear as the title attribute inside the image tag.

    Hope this helps...

  • Paul Griffiths 370 posts 1021 karma points
    Sep 04, 2013 @ 14:52
    Paul Griffiths
    0

    Hey Dan,

    Thanks for the quick response man. Ive been struggling away at that for around two hours and tried your way and bang! its doing exactly what I want! I should of come pleading for help alot sooner lol.All i was missing really was $currentPage/"name of property"

    Thanks for your help! Sorted

    Paul

     

  • Dan 1288 posts 3921 karma points c-trib
    Sep 04, 2013 @ 14:55
    Dan
    0

    Been there :)

    Honestly if you need help don't be afraid to ask on these forums. XSLT takes a different mind-set and the folks here are usually more than happy push you towards that 'lightbulb' moment.

  • Paul Griffiths 370 posts 1021 karma points
    Sep 04, 2013 @ 15:00
    Paul Griffiths
    1

    Cool!

    Yeah to be honest when your just starting out there seems to be lots of little things that can really trip you up but i must admit I whenever Ive been struggling 9/10 i will get the answer posted on here! They are really good and helpful which is just what someone like myself needs :)!

    Thanks again it was a BIG help ;)

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft