Copied to clipboard

Flag this post as spam?

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


  • TomLeads 20 posts 42 karma points
    Jan 14, 2011 @ 15:23
    TomLeads
    0

    NOOB help. Displaying page thumbnail

    Hi all. Just dipping my toe in the Umbraco waters. I want to extend one of the built in XLST templates (or just use a new one from scratch if I need to).

    I have a Listings page and on that page I want to display the children of that page, and along side the title (which I currently have), a thumbnail (date type = 'propertyThumbnail') and potentially other data types for that page.

    I've tried a few techniques but they haven't worked as I think they are using the old code format?

    The propertyThumbnail is currently a Media Picker, in case that makes a difference?

    So if anyone can help, that would be great. Thanks

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul id="nav">
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 14, 2011 @ 15:29
    Dirk De Grave
    0

    Before we move on, what's the datatype of your propertyThumbnail property? Is it a media picker, an upload? Something else? Does it have to be thumbnail of an uploaded image.

     

    Let us know and we'll see how we can help you.

     

    Cheers,

    /Dirk

  • TomLeads 20 posts 42 karma points
    Jan 14, 2011 @ 15:40
    TomLeads
    0

    Hi Dirk.

    the data type is Media Picker. And we intend for to always be an image. So they upload an image to the media gallery and then choose from that, rather than uploading straight from their machine.

    On the detail page, I can get the src of the image to be "0001" (or whatever it is), so I need to bring back the fullpath? But anyway, that is another issue.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 14, 2011 @ 15:54
    Dirk De Grave
    0

    If datatype is media picker, then the id of the media item is stored. And using umbraco.library:GetMedia(nodeId, false()), you can get info on the media item, including the full path

     

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

     

    will get you the full path of the media item

    (Assuming alias of your property for the media picker is 'propertyThumbnail')

     

    Cheers,

    /Dirk

  • TomLeads 20 posts 42 karma points
    Jan 14, 2011 @ 16:05
    TomLeads
    0

    Putting that in my XLST and trying to save gives me loads of errors

     

    System.OverflowException: Value was either too large or too small for an Int32.


    at System.Convert.ToInt32(Double value)


    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 (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)


    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)


    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,
    XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter
    writer)


    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)


    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String
    fileName, String oldName, String fileContents, Boolean ignoreDebugging)
  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 14, 2011 @ 21:16
    Kim Andersen
    0

    Hi Tom.

    the errors occours because Umbraco tries to run the code when you save the file. This means that the GetMedia extension will fail. So try wrapping the line inside of a <xsl:if> like this:

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

    This should give you the full pah to the image, without throwing an error when you save he file.

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 14, 2011 @ 21:19
    Jan Skovgaard
    0

    Hi Tom

    I'll just like to make an addition to the above. You can see some good examples on the usage of the GetMedia extension in the wiki here: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    /Jan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 14, 2011 @ 21:20
    Kim Andersen
    0

    Oh, and of course if you want to render the path in an image-tag you can do like this:

    <xsl:if test="propertyThumbnail != ''">
    <xsl:variable name="media" select="
    umbraco.library:GetMedia(propertyThumbnail, false())" />
       <img src="{
    $media/umbracoFile}" alt="{$media/@nodeName}" />
    </xsl:if>

    /Kim A

  • TomLeads 20 posts 42 karma points
    Jan 20, 2011 @ 17:28
    TomLeads
    0

    Hi guys. I'm actually prefering the syntax using the Razor scripting.

    I've been looking at this thread, but still can't get the image to display:

    http://our.umbraco.org/forum/developers/api-questions/16293-Calling-the-Umbraco-GetMedia-function-from-Razor-macro

    current code

    <ul class="listings">
    @foreach(var page in Model.Children) {
      <li>
        <h2><a href="@page.Url" title="@page.Name"><img src="@umbraco.library.GetMedia(System.Int32.Parse(page.propertyThumbnail), false)/umbracoFile"/> @page.Name</a></h2>
        <p>@page.overview</p>

      </li>
    }
    </ul>

    Which gives me some horrible feedback

    An unknown error occured while rendering the following code:

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'numberOfBedroom' at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at RazorEngine.Dynamic.fdedabeaadce.Execute() at RazorEngine.Templating.TemplateService.Parse[T](String template, T model, String name) at umbraco.MacroEngines.RazorEngine.GetResult(String cacheIdentifier, String template, INode currentPage, String& result)

    Your Razor template:

    <ul class="listings"> @foreach(var page in Model.Children) { <li> <h2><a href="@page.Url" title="@page.Name"><img src="@umbraco.library.GetMedia(System.Int32.Parse(page.propertyThumbnail), false)/umbracoFile"/> @page.Name</a></h2> <p>@page.overview</p> <a class="more" href="@page.Url">More details @page.numberOfBedroom bedrooms and brochure</a> </li> } </ul>

    Cache key:

    1053-ForSale-

  • TomLeads 20 posts 42 karma points
    Jan 25, 2011 @ 10:09
    TomLeads
    0

    And I'm back :)

    OK so the error was my fault.

    But still no joy displaying an image using the Razor file. Any thoughts?

    @foreach(var page in Model.Children) {
        <h2><a href="@page.Url" title="@page.Name"><img src="@umbraco.library.GetMedia(System.Int32.Parse(page.propertyThumbnail), false)/umbracoFile"/></a></h2>
       
    
    
                
Please Sign in or register to post replies

Write your reply to:

Draft