Copied to clipboard

Flag this post as spam?

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


  • Michael 8 posts 28 karma points
    Sep 12, 2011 @ 15:17
    Michael
    0

    Use of GetMedia after upgrade to 4.5 with LegacyXmlShema on

    Hi,

    Recently i have upgraded my Umbraco website from 4.0 to 4.5 with the UseLegacyXmlSchema setting on true.

    Now i try to make some customasible content blocks with image, title and text. Unfortunately i can't get the GetMedia property work.

    What is the good work-around for this?

    Currently i use inline XSLT:
    <umbraco:Item runat="server" field="ccZwemABCImage" xslt="concat('&lt;img src=&quot;',umbraco.library:GetMedia({0}, true())/umbracoFile, '&quot; /&gt;')" xsltDisableEscaping="true"/>

    Thanks,

    Michael

     

  • Rich Green 2246 posts 4008 karma points
    Sep 12, 2011 @ 15:28
    Rich Green
    0

    Hey Michael,

    Welcome to the forum!

    Your code seems to be using the new schema? A pre 4.5 sample can be found here http://our.umbraco.org/wiki/reference/templates/umbracoitem-element/inline-xslt

    Something like

    <umbraco:Item runat="server" field="ccZwemABCImage" xslt="concat('&lt;img src=&quot;',umbraco.library:GetMedia({0}, true())/data[@alias='umbracoFile'], '&quot; /&gt;')" xsltDisableEscaping="true"/>

    Rich


     

  • Michael 8 posts 28 karma points
    Sep 12, 2011 @ 15:33
    Michael
    0

    Hi Rich,

    Thank you for your comment!

    Unfortunately i tried every snippet from the pages above, without result.

  • Rich Green 2246 posts 4008 karma points
    Sep 12, 2011 @ 15:43
    Rich Green
    0

    Hi,

    What does the following return?

    <umbraco:Item runat="server" field="ccZwemABCImage" /> 

    Rich

  • Michael 8 posts 28 karma points
    Sep 12, 2011 @ 15:51
    Michael
    0

    Hi Rich,

    That snippet returns the image ID.

    Michael

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 12, 2011 @ 15:55
    Fuji Kusaka
    0

    Hi Michael,

    Can you try this instead

    <umbraco:Item runat="server" field="ccZwemABCImage" xslt="concat('&lt;img src=&quot;',umbraco.library:GetMedia({0}, true())/umbracoFile, '&quot; /&gt;')" xsltDisableEscaping="true"/>
  • Michael 8 posts 28 karma points
    Sep 12, 2011 @ 16:02
    Michael
    0

    Hi Fuji,

    That unfortunately leaves a empty <img src="" /> too.

    Michael

  • Richard 146 posts 168 karma points
    Sep 12, 2011 @ 16:12
    Richard
    0

    An alternative approach would be to create an XSLT macro that outputs the IMG tag, and pass the media ID or as in this example the page property of the current page (e.g. ccZwemABCImage)  to the XSLT. I have used this on Umbraco 4.0 sites that have been upgraded to 4.5.2. 

    <xsl:variable name="pageProperty" select="/macro/PageProperty"/>

    <xsl:template match="/">

    <xsl:if test="string-length($pageProperty) &gt; 0">
    <xsl:if test="$currentPage/data [@alias=$pageProperty] != ''">

    <xsl:call-template name="imageFromId">
    <xsl:with-param name="imageid" select="$currentPage/data [@alias=$pageProperty]"/>
    </xsl:call-template>
    </xsl:if>
    </xsl:if>

    </xsl:template>

    <!-- Output IMG tag from media node id -->
    <xsl:template name="imageFromId">
    <xsl:param name="imageid"/>

    <xsl:if test="$imageid!=''">
    <xsl:variable name="image" select="umbraco.library:GetMedia($imageid, 'false')"/>

    <img src="{$image/data[@alias = 'umbracoFile']}" width="{$image/data[@alias = 'umbracoWidth']}" height="{$image/data[@alias = 'umbracoHeight']}" alt="{$image/@nodeName}"/>
    </xsl:if>
    </xsl:template>
  • Michael 8 posts 28 karma points
    Sep 15, 2011 @ 12:24
    Michael
    0

    I have decided to use the new XML schema and everything is fine now with the code below:

      <xsl:if test="$currentPage/ccZwemABCImage !=''">
        <img src="{umbraco.library:GetMedia($currentPage/ccZwemABCImage, 0)/umbracoFile}" />
      </xsl:if>

    Thanks for your comments!

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 15, 2011 @ 12:26
    Fuji Kusaka
    0

    Hi Michael,

    Well good to hear you got it working though.

Please Sign in or register to post replies

Write your reply to:

Draft