Copied to clipboard

Flag this post as spam?

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


  • Klaus 47 posts 67 karma points
    Jul 13, 2011 @ 19:54
    Klaus
    0

    Media Picker - how does it work

    Hello,

    I guess that this is a very basic question for some of you, so hope that you can help here. I have been searching the internet for tutorials and guides on how to use media picker in combination with xslt, but i seem to get it wrong.

    1) I createt a property under one of my Documents Types -> I called it Media Item and alias mediaItem.

    2) I created a xslt document and a macro and put in the following code:

    <?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"
        exclude-result-prefixes="msxml umbraco.library">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
      <xsl:variable name="mediaId" select="number($currentPage/data[@alias='mediaId'])" />
      <xsl:if test="$mediaId &gt; 0">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
        <xsl:if test="count($mediaNode/data) &gt; 0 and string($mediaNode/data[@alias='umbracoFile']) != ''">
          <img src="{$mediaNode/data[@alias='umbracoFile']}" alt="[image]" height="{$mediaNode/data[@alias='umbracoHeight']}" width="{$mediaNode/data[@alias='umbracoWidth']}" />
        </xsl:if>
      </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    3) I created a macro called Billede.

    4) I added the Macro to my template as follow: <umbraco:Macro Alias="Billede" runat="server"></umbraco:Macro><br>

     

    I don't get it. How does it all fit together - can anyone please take a look, and tell me what is wrong.


    Best Regards

    Klaus

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 13, 2011 @ 20:12
    Dennis Aaen
    0

    Hi Klaus,

    I just took a look at your code. What the immediately just to see may be the problem is this line.

    <xsl:variable name="mediaId" select="number($currentPage/data[@alias='mediaId'])" />

    Try something like, hope it helps you

    <xsl:variable name="mediaId" select="number($currentPage/data[@alias='mediaItem'])" />

    I should also just be sure that you only create the macro in the creation of xslt file. You write: the point 3 that you create a macro. But is this not created in connection with the xslt file creation.

    Hope this can help to solve your question.

    /Dennis

  • Klaus 47 posts 67 karma points
    Jul 13, 2011 @ 20:36
    Klaus
    0

    Hallo Dennis,

    Yes, when i created the my Billed.xslt it also created the Billed macro. The Billed macro does not have any parameters.

    I changed the code as you explained above, but unfortunately, nothing changed. I also tried to delete the image under my article and uploade a new image, but without luck.

    Any suggestions?

    /klaus

  • Klaus 47 posts 67 karma points
    Jul 13, 2011 @ 20:44
    Klaus
    0

    I guess that the mediaItem is the property of the Media Picker in my Document Types? Or how does it work?

    /Klaus

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 13, 2011 @ 21:03
    Chriztian Steinmeier
    1

    Hi Klaus,

    My guess would be that you've found some XSLT for the old version of the XML schema - here's something that'll work with Umbraco 4.5 and later (just replace your existing <xsl:template match="/"> ... </xsl:template> with these two templates):

      <xsl:template match="/">
            <xsl:apply-templates select="$currentPage/mediaItem[normalize-space()]" />
        </xsl:template>
    
        <xsl:template match="mediaItem">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" />
            <xsl:if test="not($mediaNode[error])">
                <img src="{$mediaNode/umbracoFile}" width="{$mediaNode/umbracoWidth}" height="{$mediaNode/umbracoHeight}" alt="[image]" />
            </xsl:if>
        </xsl:template>
    
    If you are using the old schema, let me know and I'll provide a backwards-compatible version for you.

    /Chriztian

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 13, 2011 @ 21:08
    Dennis Aaen
    0

    Hi agin Klaus,

    I'll try to help as best I can.
    I gotta hear it's just a media picker will print an image on the page you stand on the content tree.

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/data[@alias='mediaItem'], 0)/data [@alias = 'umbracoFile']"/>

    <xsl:if
    test="$media!=''">
           
    <img src="{$media}"/>
    </xsl:if>

    If so, I think you can do it that way. Must just say I do not have much experience with this old xml schema in Umbraco.

    /Dennis

  • Klaus 47 posts 67 karma points
    Jul 13, 2011 @ 21:24
    Klaus
    0

    Hello again,

    I works with the new snippet Christian gave me - thanks a lot.

    I just have one issue now. I shows two images of the same? Any idea why?

     

    /Klaus

  • Klaus 47 posts 67 karma points
    Jul 13, 2011 @ 21:32
    Klaus
    0

    Okay my bad - i overwrite another xlts with the code you gave me - stupid idiot i am.

    //Thanks alot for your help.

    /Klaus

  • Lou 59 posts 169 karma points
    Nov 16, 2011 @ 23:26
    Lou
    0

    I am using Media Picker to select images in a collection. I want to access this collection for a slide show.  I inherited code from another developer who was using File Upload to add pictures to the Collection of Images, this worked fine, except that we end up with a lot of images, and the images can't be easily shared.  So I changed the File Upload to a Media Picker and no image was displayed.  When I view page source the error is obvious.

    I am using the following;

    img src="{umbraco.library:GetMedia(picture,false)}" 

    And I get this

    img src="/media/10580/picked2.jpg760250137819jpg"

    When the image I want is this

    img src="/media/10580/picked2.jpg"


     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 16, 2011 @ 23:33
    Chriztian Steinmeier
    0

    Hi Lou,

    You can use:

    <img src="{umbraco.library:GetMedia(picture, false())/umbracoFile}" />

    to get right to the path - it mandates that there is a picture picked in the Media Picker, otherwise it will fail (hard).

    Feel free to start a separate thread if you have more questions - that way it's easier for everyone to find a single answer to a specific question.

    /Chriztian

  • Lou 59 posts 169 karma points
    Nov 16, 2011 @ 23:50
    Lou
    0

    Thank You Chriztian, it works now.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies