Copied to clipboard

Flag this post as spam?

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


  • Robin 37 posts 109 karma points
    Nov 01, 2014 @ 13:14
    Robin
    0

    Get ID of currentmedia image

    Hello,

    I'm trying to show an image chosen from a currentMedia parameter (called imageParam) in a Marco. I try to do it like the code below, but I can't get my ID. The 'imageParam' contains all the information, and if I try to get only the ID I get the whole thing or nothing. What am I doing wrong?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:param name="imageParam" select="/macro/imageParam/Image/@id" />

    <xsl:template match="/">
    <textarea>
    <xsl:copy-of select="macro/imageParam" />
    </textarea>
    <xsl:if test="$imageParam !=''">
    <xsl:value-of select="umbraco.library:GetMedia($imageParam, 0)/umbracoFile" />
    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>

     

    The textbox gives me:

    <imageParam><Image id="1918" version="6ff935c2-7688-436e-965e-c1383eff557b" parentID="1327" level="2" writerID="0" nodeType="1032" template="0" sortOrder="0" createDate="2014-07-25T20:16:25" updateDate="2014-07-25T20:16:28" nodeName="xxxxxxxxx" urlName="xxxxxxxx" writerName="Robin" nodeTypeAlias="Image" path="-1,1327,1918"><umbracoFile>/media/33144/xxxxxxxxx.jpg</umbracoFile><umbracoWidth>3400</umbracoWidth><umbracoHeight>834</umbracoHeight><umbracoBytes>348763</umbracoBytes><umbracoExtension>jpg</umbracoExtension></Image></imageParam>

    It's the '1918' I need, what is also in my macro:

    <umbraco:Macro imageParam="1918" Alias="xxxxxxxx" runat="server"></umbraco:Macro>

     

    Robin

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 01, 2014 @ 14:20
    Dennis Aaen
    100

    Hi Robin,

    Try this code, this should print out the image that you choose as the param when you add the marco to the template. I have added so it write an alt tag with the name of the image and added width and height of the image too.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
       version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
       <xsl:param name="currentPage"/>
     <xsl:param name="imageParam" select="/macro/imageParam/Image/@id" />

      <xsl:template match="/">     
       
      <xsl:if test="$imageParam !=''">
              <xsl:variable name="media" select="umbraco.library:GetMedia($imageParam, 0)" />
            <xsl:variable name="url" select="$media/umbracoFile" />
            <xsl:variable name="width" select="$media/umbracoWidth" />
            <xsl:variable name="height" select="$media/umbracoHeight" />
              <xsl:variable name="alt" select="$media/@nodeName" />
              
              <img src="{$url}" width="{$width}" height="{$height}" alt="{$alt}" />

      </xsl:if>

    </xsl:template>

    </xsl:stylesheet>

    Hope this helps,

    /Dennis

  • Robin 37 posts 109 karma points
    Nov 01, 2014 @ 14:45
    Robin
    0

    Thanks a lot :)
    I was looking it to far I gues.

    There is something I don't understand, I totally understand this '/macro/imageParam/Image/@id' but when I want to 'print' this on the screen in a textbox like below, I just get the rest of the HTML from my page in the box. Why is this? I thought it was because '/macro/imageParam/Image/@id' returned nothing but appearently I was wrong (becaus your code does work).

    <textarea>
    <xsl:copy-of select="/macro/imageParam/Image/@id" />
    </textarea>

     

    Robin

Please Sign in or register to post replies

Write your reply to:

Draft