Copied to clipboard

Flag this post as spam?

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


  • Sophie Mitchell 23 posts 43 karma points
    Jan 20, 2012 @ 17:00
    Sophie Mitchell
    0

    Help with mediapicker

    Hi,

    I'm very new to Umbraco and at the moment I'm struggling with my news listing page. I'd like to be able to add a thumbnail image to each news item to display only in the news list - not in the news item detail page.

    Here's what I've done:

    In my news item document type. I've added the property of image, type media picker. I've added that the summary section.

    Now when I go to the content, news item I can add an image using the mediapicker.

    To display it in my newslist XSLT file I have added <xsl:value-of select="image"/>. On the website I now see a number 1115 - where the image should be.

    I'm sure I'm going about this the wrong way - using the wrong code or something but I can't seem to find or workout the solution. Can anyone help?

    Thanks


  • Rodion Novoselov 694 posts 859 karma points
    Jan 20, 2012 @ 17:06
    Rodion Novoselov
    0

    The number you see is the ID of an image in the media library. To get the image node itself you can use umbraco.library:GetMedia(image, 0)

  • Jon 36 posts 59 karma points
    Jan 20, 2012 @ 17:06
    Jon
    0

    The number is a unique identifier for the media item, you'll need to use the 'GetMedia' function in your XSLT:

    http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 17:13
    Jeroen Breuer
    0

    You could also try DAMP. It can store the media xml so you don't need to use library:GetMedia.

    Jeroen

  • Sophie Mitchell 23 posts 43 karma points
    Jan 20, 2012 @ 17:42
    Sophie Mitchell
    0

    Thank you.

    How do I actually umbraco.library:GetMedia(image, 0) to the code? I've had a look through the getmedia wiki before and tried all the options but again I'm doing something wrong because I get this error on the web page Error parsing XSLT file: \xslt\NewsList2.xslt

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 20, 2012 @ 17:47
    Jan Skovgaard
    0

    Hi Sophie

    Could you try adding ?umbdebugshowtrace=1 to the url in the browser window - this will give you a stack trace, which may contain an error message marked with red.

    If it contains an error message then please post it in here :) Also please post the whole code so it's easier for others to try and figure out where the problem is.

    /Jan

  • Sophie Mitchell 23 posts 43 karma points
    Jan 20, 2012 @ 17:59
    Sophie Mitchell
    0

    Thanks Jan. 

    My page code is this:

    <?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:variable name="source" select="/macro/source"/>
    <xsl:variable name="maxItems" select="/macro/maxItems"/>

        <xsl:template match="/">

    <ul>

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
      
    <xsl:sort select="@createDate" order="descending" />
    <xsl:if test="position() &lt;= $maxItems">
      
      <li>
        <h2><a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
          </a></h2>
       
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='image'], 0)/data [@alias = 'image']"/>
       
        <p>
        <xsl:value-of select="summary"/>
        </p>
        
      </li>
      </xsl:if>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>

     

    I got this red code when I added the bugtrace details:

    umbracoMacro
    InnerException

    Value was either too large or too small for an Int32.
    Value was either too large or too small for an Int32.
      at System.Convert.ToInt32(Double value)
      at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
      at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
      at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
      at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
      at System.Xml.Xsl.CompiledQuery.Query.<xsl:template match="/">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, Double {urn:schemas-microsoft-com:xslt-debug}position, Double {urn:schemas-microsoft-com:xslt-debug}last, IList`1 {urn:schemas-microsoft-com:xslt-debug}namespaces) in C:\Inetpub\wwwroot\cms\xslt\NewsList2.xslt:line 30
      at System.Xml.Xsl.CompiledQuery.Query.<xsl:apply-templates>(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator , Double , Double )
      at System.Xml.Xsl.CompiledQuery.Query.Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
      at System.Xml.Xsl.CompiledQuery.Query.Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
      at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
      at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
      at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
      at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
      at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters)
      at umbraco.macro.loadMacroXSLT(macro macro, MacroModel model, Hashtable pageElements)

    0.995837739153999

    0.025523
     

    Thank you! 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 18:01
    Jeroen Breuer
    0

    Could you post part of you umbraco.config file so we can see how the xml looks? This error usually happens when you use librery.GetMedia, but the parameter isn't an id.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 18:03
    Jeroen Breuer
    1

    Hmm are you using the latest Umbraco? In that case you need to use the new xml. Try this:

     <xsl:value-of select="umbraco.library:GetMedia($currentPage/image], 0)/umbracoFile"/>

    Jeroen

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 20, 2012 @ 18:04
    Jan Skovgaard
    0

    Also it seems like you have a mix of new and old XML schema in the code. But let's see the umbraco.config as Jeroen says and then we can help you out from there :)

    /Jan

  • Rodion Novoselov 694 posts 859 karma points
    Jan 20, 2012 @ 18:04
    Rodion Novoselov
    0

    Your Xslt is compatible with old XML schema, not a new one. If your intallation is running a new schema

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='image'], 0)/data [@alias = 'image']"/>
    

    should be spelled as:

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/image, 0)/umbracoFile"/> 

    or like that if you want some other media properties instead of "umbracoFile".

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 20, 2012 @ 18:05
    Jan Skovgaard
    0

    Aaah, too slow :D

    Well spotted Jeroen.

    /Jan

  • Rodion Novoselov 694 posts 859 karma points
    Jan 20, 2012 @ 18:06
    Rodion Novoselov
    0

    me too :-)

  • Sophie Mitchell 23 posts 43 karma points
    Jan 20, 2012 @ 18:18
    Sophie Mitchell
    0

    Thanks again all of you. It could well be a mix of lots of things, I was kind of given this as asked to make it work. So I've been watching the videos etc and working it out as I go along.

    I tried this <xsl:value-of select="umbraco.library:GetMedia($currentPage/image, 0)/umbracoFile"/> and I still get the same error.

    How much of the config file do you need to see? 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 18:22
    Jeroen Breuer
    0

    If you can find the node which you are currently using to display the image that would be enough :).

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 18:30
    Jeroen Breuer
    0

    It seems that you could use some good examples. Why not try Cultiv Razor Examples? It's a complete Umbraco website (not a package) and has some nice examples how media can be used in Razor (if you want to use that). Or watch this video on how to install DAMP. It has examples for Razor and XSLT.

    Jeroen

  • Sophie Mitchell 23 posts 43 karma points
    Jan 20, 2012 @ 18:32
    Sophie Mitchell
    0

    Here?

    <newAreaIntroduction><![CDATA[

    Our company news

    ]]></newAreaIntroduction>

          <umbracoNaviHide>1</umbracoNaviHide>

          <NewNewsItem id="1112" parentID="1102" level="3" writerID="1" creatorID="1" nodeType="1109" template="1110" sortOrder="2" createDate="2011-10-20T11:34:03" updateDate="2012-01-20T15:01:00" nodeName="News two" urlName="news-two" writerName="Info" creatorName="Info" path="-1,1050,1102,1112" isDoc="">

            <summary><![CDATA[Summary here]]></summary>

            <bodyText><![CDATA[

    content here

    ]]></bodyText>

            <image />

          </NewNewsItem>

          <NewNewsItem id="1120" parentID="1102" level="3" writerID="1" creatorID="1" nodeType="1109" template="1110" sortOrder="3" createDate="2012-01-12T17:02:15" updateDate="2012-01-20T16:27:01" nodeName="Testing the third one" urlName="testing-the-third-one" writerName="Info" creatorName="Info" path="-1,1050,1102,1120" isDoc="">

            <summary><![CDATA[Adding a little content here]]></summary>

            <bodyText><![CDATA[

    Proper content in here

    ]]></bodyText>

            <image>1113</image>

          </NewNewsItem>

          <NewNewsItem id="1111" parentID="1102" level="3" writerID="1" creatorID="1" nodeType="1109" template="1110" sortOrder="4" createDate="2011-10-20T11:30:02" updateDate="2011-10-20T11:35:02" nodeName="News one" urlName="news-one" writerName="Info" creatorName="Info" path="-1,1050,1102,1111" isDoc="">

            <summary><![CDATA[testing summary]]></summary>

            <bodyText><![CDATA[

    testing content

    ]]></bodyText>

          </NewNewsItem>

        </News> 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 18:38
    Jeroen Breuer
    0

    Hmm I see this:

    <image />
    <image>1113</image>

    Both should have an id. That's what is causing the error. Please select a media item for both pages and try again.

    Jeroen

  • Sophie Mitchell 23 posts 43 karma points
    Jan 20, 2012 @ 18:53
    Sophie Mitchell
    0

    I've added an image for each news item and now I see:

     <NewNewsItem id="1112" parentID="1102" level="3" writerID="1" creatorID="1" nodeType="1109" template="1110" sortOrder="2" createDate="2011-10-20T11:34:03" updateDate="2012-01-20T17:49:50" nodeName="News two" urlName="news-two" writerName="Info" creatorName="Info" path="-1,1050,1102,1112" isDoc="">

            <summary><![CDATA[Summary here]]></summary>

            <bodyText><![CDATA[

    content here

    ]]></bodyText>

            <image>1114</image>

          </NewNewsItem>

          <NewNewsItem id="1120" parentID="1102" level="3" writerID="1" creatorID="1" nodeType="1109" template="1110" sortOrder="3" createDate="2012-01-12T17:02:15" updateDate="2012-01-20T17:49:57" nodeName="Testing the third one" urlName="testing-the-third-one" writerName="Info" creatorName="Info" path="-1,1050,1102,1120" isDoc="">

            <summary><![CDATA[Adding a little content here]]></summary>

            <bodyText><![CDATA[

    Proper content in here

    ]]></bodyText>

            <image>1114</image>

          </NewNewsItem>

          <NewNewsItem id="1111" parentID="1102" level="3" writerID="1" creatorID="1" nodeType="1109" template="1110" sortOrder="4" createDate="2011-10-20T11:30:02" updateDate="2012-01-20T17:50:03" nodeName="News one" urlName="news-one" writerName="Info" creatorName="Info" path="-1,1050,1102,1111" isDoc="">

            <summary><![CDATA[testing summary]]></summary>

            <bodyText><![CDATA[

    testing content

    ]]></bodyText>

            <image>1114</image>

          </NewNewsItem>

    And I still get the same error with the macro - is there something I should do with that?

    Thanks again 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 19:40
    Jeroen Breuer
    0

    I looked at your XSLT file again. You're looping through some nodes which have a property with the alias 'image', but the examples we used the current page. So try this in your XSLT

    <xsl:value-of select="umbraco.library:GetMedia(./image, 0)/umbracoFile"/>

    Now it's using the node you're looping trough.

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 21, 2012 @ 09:40
    Rodion Novoselov
    0

    You can just add an "<xsl:if>" clause to validate that the "image" field is not empty: 

    <xsl:if test="string(image) != ''"> 
        <xsl:value-of select="umbraco.library:GetMedia(image, 0)/umbracoFile"/>
    </xsl:if>

    That will preven the error in such a case.

  • Sophie Mitchell 23 posts 43 karma points
    Jan 24, 2012 @ 13:46
    Sophie Mitchell
    0

    Thank you both - that is definitely an improvement!

    I now have no error and it's clearly trying to show the image so now I get title followed by /media/463/rock_cakes.jpg and then the summary.

    Let me know if you need the code.

    Thank you 

  • Jon 36 posts 59 karma points
    Jan 24, 2012 @ 13:56
    Jon
    0

    If your code is still similar to what you posted above above:

     <li>
        <h2><a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
          </a></h2>
    
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='image'], 0)/data [@alias = 'image']"/>
    
        <p>
        <xsl:value-of select="summary"/>
        </p>
    
      </li>

    Then you will need an 'img' tag:

     <li>
        <h2><a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
          </a></h2>
    
        <img src="{umbraco.library:GetMedia(image, 0)/umbracoFile}" />
    
        <p>
        <xsl:value-of select="summary"/>
        </p>
    
      </li>
  • Sophie Mitchell 23 posts 43 karma points
    Jan 24, 2012 @ 14:06
    Sophie Mitchell
    0

    Perfect thank you that's working!

    Thanks for all the help 

Please Sign in or register to post replies

Write your reply to:

Draft