Copied to clipboard

Flag this post as spam?

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


  • ask 28 posts 48 karma points
    Mar 03, 2011 @ 15:31
    ask
    0

    get images using mediacurrent

    hello folks,

    i have placed my images(10 images) in folder(gallery) in mediacurrent.

    how do i loop through all the images in the folder.

    i am using umbraco version 4.6.1

    thank you

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 03, 2011 @ 20:54
    Kim Andersen
    0

    Hi Ask

    Could you explain in more details what you want to achieve? I get that you want to loop through images in a folder in the media gallery, but where do you get the folder from? Are you using a media picker on a node, or is the folder comming from a macro parameter?

    If you have some existing code you could show us, it would be great so that we can make that work :)

    /Kim A

  • ask 28 posts 48 karma points
    Mar 04, 2011 @ 02:53
    ask
    0

    i am unable to edit this question..

    i have  created folder(named as gallery) under media section in umbraco backend and  will be adding images under this folder.

    then i am creating a xslt macro with parameter "mediacurrent".

    i will choose this folder(gallery) as source.

    i would like to have script for looping through images in that selected folder or something like that .

    thank you

     

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 04, 2011 @ 08:17
    Kim Andersen
    1

    Hi Ask

    I can't remember what the mediaCurrent type returns, but could you try to print out whats in the parameter like this:

    <textarea>
    <xsl:copy-of select="macro/aliasOfTheMediaCurrent" />
    </textarea>

    Then we can see what we have to work with.

    /Kim A

  • ask 28 posts 48 karma points
    Mar 04, 2011 @ 15:00
    ask
    0

    it returns as like this if i choose folder in the media section of umbraco backend

    <ImageSource>
      <Folder id="1127" version="96be8528-ad92-4904-8b17-5e8499886d48" parentID="-1" level="1"
    writerID="0" nodeType="1031" template="0" sortOrder="53" createDate="2011-03-03T19:38:41" updateDate="2011-03-03T19:38:41"
    nodeName="gallery" urlName="gallery" writerName="admin" nodeTypeAlias="Folder"
     path="-1,1127">
        <contents />
      </Folder>
    </ImageSource>

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 04, 2011 @ 15:46
    Kim Andersen
    1

    Hi Ask

    Could you try something like this then:

    <xsl:variable name="mediaNode" select="macro/aliasOfTheMediaCurrent" />
    <xsl:variabel name="id" select="$mediaNode/ImageSource/Folder/@id" />

    <xsl:variable name="folderContent" select="umbraco.library:GetMedia($id,1)" />

    Now the $folderContent should (if I didn't make any mistakes :) ) contain all of the XML that the selected folder contains, and you can run through the child nodes from there.

    Does that make sense?

    /Kim A

  • ask 28 posts 48 karma points
    Mar 07, 2011 @ 08:10
    ask
    0

    Hi kim,

    i tried this way

    <xsl:variable name="mediaNode" select="/macro/mediaSource" />
      <xsl:variable name="id" select="$mediaNode/Folder/@id" />
    <xsl:if test="$id">
       <xsl:variable name="folderContent" select="umbraco.library:GetMedia($id,1)" />
      <xsl:value-of select="$folderContent"/>
             <img src="{$folderContent}" alt="" height="200px" width="200px"/>
    </xsl:if>

    i got this output

    /media/4119/img-1.jpg24413733015jpg/media/4127/img-3.jpg24413732463jpg/media/4137/img-7.jpg11313011397jpg

    what should be schema  for newer version?

    i need to assign each image path to image src.

    thank you

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 07, 2011 @ 08:19
    Kim Andersen
    1

    Try something like this:

    <xsl:variable name="mediaNode" select="/macro/mediaSource" />
    <xsl:variable name="id" select="$mediaNode/Folder/@id" />
    <xsl:if test="$id">
       <xsl:variable name="folderContent" select="umbraco.library:GetMedia($id,1)" />

    <xsl:for-each select="$folderContent/Image">
    <img src="{umbracoFile}" alt="@nodeName" />
    </xsl:for-each>
    </xsl:if>

    I haven't tried the above piece of code, but if this doesn't work, please try to print out the $folderContent variable in a textarea, and show us the returned XML :)

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 07, 2011 @ 08:21
    Jan Skovgaard
    0

    Hi Ask

    You can read more about using the GetMedia extension here: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

     

    About the schema...when Umbraco 4.5 was released the XML schema was changed so the XSLT that needs to be written with 4.5 and above should have another syntax than the old schema. This is something that is confusing many people who are new to Umbraco since there are many examples on how to achieve stuff with XSLT in Umbraco using the old schema syntax. This is not an issue here since you get the image properties outputted.

    What you need to do to create a list of the images now is this

    <xsl:variable name="mediaNode" select="/macro/mediaSource" />
      <xsl:variable name="id" select="$mediaNode/Folder/@id" />
    <xsl:if test="$id">
       <xsl:variable name="folderContent" select="umbraco.library:GetMedia($id,1)" />

    <xsl:for-each select="$folderCOntent">
    <ul>
    <li><img src="{umbracoFile}" alt="" height="200px" width="200px"/></li>
    </ul>
    </xsl:for-each>
    </xsl:if>

    Try it out - it should to what you're requesting.

    /Jan

  • ask 28 posts 48 karma points
    Mar 22, 2011 @ 15:07
    ask
    0

    thank you Mr.kim && Mr.Jan

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 22, 2011 @ 20:55
    Kim Andersen
    0

    Ahh great news hearing from you Ask :)

    I'm glad that the solution above worked for you.

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 22, 2011 @ 21:46
    Jan Skovgaard
    0

    Hi Ask

    Happy to hear you got it solved. Just out of couriosity...what does your working code look like now? :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft