Copied to clipboard

Flag this post as spam?

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


  • Martin Vingaard 39 posts 60 karma points
    Jan 31, 2011 @ 16:04
    Martin Vingaard
    0

    Show image with mediapicker {newbie}

    Hi, im new to Umbraco, but i have worked with .NET and C# up to now.

    Atm im having a problem displaying an image from the media picker, i realize that its a common issue, and i have searched the web for a solution.

    The issue:

    I have a tab called Submenu, within it there is a property with the alias 'submenuImage01' with the type set as Media picker. I realize that this will get me the ID of the image.

    I want to display the image set as submenuImage01.

    I've been working in within the xslt editor, and havent yet been able to fetch the correct data.

    This is my code as it is now:

    <xsl:template match="/">

    <xsl:if test="$currentPage/data[@alias='submenuImage01'] = ''">
    <img src="{umbraco.library:GetMedia($currentPage/data[@alias='submenuImage01'],0)/data[@alias='umbracoFile']}" />
    </xsl:if>


    </xsl:template>

     

    Thanks in advance

  • Kim Andersen 1447 posts 2194 karma points MVP
    Jan 31, 2011 @ 16:08
    Kim Andersen
    1

    Hi Martin

    Which version of Umbraco are you using? Or actually I'd like to know which version of the XML schema you are using.

    If you are using the "new" XML schema please try this snippet:

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

    /Kim A

  • Kim Andersen 1447 posts 2194 karma points MVP
    Jan 31, 2011 @ 16:11
    Kim Andersen
    1

    Ohh and I can just see another small error if you are actually using the legacy schema. Then you need to change this:

    <xsl:if test="$currentPage/data[@alias='submenuImage01'] = ''">

    to this:

    <xsl:if test="$currentPage/data[@alias='submenuImage01'] != ''">

    The difference is that you are saying if the media picker IS empty, then render the image. But it should of course be if the media picker IS NOT empty, then render the image.

    /Kim A

  • Martin Vingaard 39 posts 60 karma points
    Jan 31, 2011 @ 17:26
    Martin Vingaard
    0


    Im using Umbraco 4.6.1

    I made the change, since it should ofc only load the img if there is one.

    Here is my xsl document.

    <?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:template match="/">

    <xsl:if test="$currentPage/data[@alias='submenuImage01'] != ''">
    <img src="{umbraco.library:GetMedia($currentPage/data[@alias='submenuImage01'],0)/data[@alias='umbracoFile']}" />
    </xsl:if>


    </xsl:template>

    </xsl:stylesheet>

    Thanks for the quick response 

  • Jan Skovgaard 11245 posts 23462 karma points MVP 6x admin c-trib
    Jan 31, 2011 @ 17:34
    Jan Skovgaard
    0

    Hi Martin

    The reason for your trouble is that the code you posted is using the old XML schema, which is not used since Umbraco 4.5 came out. It can howeber be changed in the umbracoSettings.config to use the old schema. But that's probably out of scope for this topic :-)

    But new users to Umbraco often (and very understandably) gets confused about this, since they find many XSLT examples, which has been written for version of Umbraco earlier than 4.5.

    So what you need to do is to alter the code to this

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

    This should be working I think.

    /Jan

  • Martin Vingaard 39 posts 60 karma points
    Jan 31, 2011 @ 17:43
    Martin Vingaard
    0

    That worked.. (deleted the ' after umbracoFile')

    Thanks for the help guyes.

  • TomLeads 20 posts 42 karma points
    Feb 03, 2011 @ 11:18
    TomLeads
    0

    Guys, I also need to get an image (well, several images back from the media picker. using the above code, and trying the fix, doesn't work for me:

    <?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:template match="/">

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

    </xsl:template>

    </xsl:stylesheet>

    gives me errors

    Error occured

    System.Xml.Xsl.XslLoadException: String literal was not closed.
    ...urrentPage/photo1,0)/umbracoFile -->'}<-- An error occurred at C:\projects\HomeNow\Main\HomeNow\xslt\634323250997212466_temp.xslt(17,1).
    at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

    I am a absolute noob when it comes to XLST. Sorry.

  • TomLeads 20 posts 42 karma points
    Feb 03, 2011 @ 11:20
    TomLeads
    0

    Ooops, ignore me completely! It did work, I missed the comment before mine about removing the '

    final code for reference:

    <?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:template match="/">

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

    </xsl:template>

    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft