Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 11, 2012 @ 15:41
    Fuji Kusaka
    0

    Displaying a the first image of a media picker from parent node

    Hi all,

    Is it possible to display the 1st image of a media picker from its parent node??

    <ul>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
      
      <li>  <img src="{umbraco.library:GetMedia(@id, 'false')/PhotoGallery[1]/umbracoFile}" /></li>
        </xsl:for-each> 
     
    </ul>
  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Apr 11, 2012 @ 16:08
    Chriztian Steinmeier
    0

    Hi Fuji,

    Yes - it's possible - but you should make sure only to fetch all the media items once (!)

    If the Media Picker on $currentPage selects a folder, you can do this:

    <!-- Provide the right id here: -->
    <xsl:variable name="topFolderId" select="1700" />
    
    <!-- Fetch all media below that folder: -->
    <xsl:variable name="media" select="umbraco.library:GetMedia($topFolderId, true())" />
    
    <xsl:template match="/">
        <ul>
            <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">
                <li>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="@nodeName"/>
                    </a>
                </li>
                <li>
                    <!-- Show the first image in the folder picked by the Media Picker property on currentPage -->
                    <xsl:apply-templates select="$media//Folder[@id = current()/mediaPickerProperty]/Image[1]" />
                </li>
            </xsl:for-each>
        </ul> 
    </xsl:template>
    
    <!-- Template for the image -->
    <xsl:template match="Image">
        <img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" alt="{@nodeName}" />
    </xsl:template>

    /Chriztian 

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 11, 2012 @ 16:25
    Fuji Kusaka
    0

    Hi Chriztian,

     

    Thanks for the reply, i have try but not getting any info. Jus for the record i have my own Media Type " PhotoGallery" since i  have a cropping there. 

      <xsl:variable name="topFolderId" select="1760" />
        
        <xsl:variable name="media" select="umbraco.library:GetMedia($topFolderId, true())/PhotoGallery" />
    <xsl:template match="/">

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

    </xsl:template>
        
        <!-- Template for the image -->
    <xsl:template match="Image">
            <img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" alt="{@nodeName}" />
    </xsl:template>

    I tried to add the Id of the Parent which is 1760 but i nothing is showing up. Here i only want the Parent to show the first Image of my mediapicker from the child node.

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Apr 11, 2012 @ 16:33
    Chriztian Steinmeier
    0

    Hi Fuji,

    You should remove the /PhotoGallery part from the media variable - you need the Folders in there to be able to select their first-child elements. 

    You'll also need to change the "Image" template to match "PhotoGallery" elements instead - you can just add it, e.g.:

    <xsl:template match="Image | PhotoGallery">
       ... 
    </xsl:template>

    /Chriztian 

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 11, 2012 @ 16:41
    Fuji Kusaka
    0

    Nope still nothing is showing up. I also try to add some dummy text in the Template but nothing is showing up.

    <xsl:param name="currentPage"/>
        <xsl:variable name="topFolderId" select="1760" />    
        <xsl:variable name="media" select="umbraco.library:GetMedia($topFolderId, true())" />
        <xsl:template match="/">
    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>  
      <li>
                 <!-- Show the first image in the folder picked by the Media Picker property on currentPage -->
            <xsl:apply-templates select="$media//Folder[@id = current()/galleryPicker]/PhotoGallery[1]/umbracoFile" />
    Here i addded my galleryPicker alias am using for my mediaPicker on the child node
         </li>
      </xsl:for-each>     
    </ul>
    </xsl:template>    
        <!-- Template for the image -->
    <xsl:template match="PhotoGallery">
      <img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" alt="{@nodeName}" />
    </xsl:template
  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Apr 11, 2012 @ 16:47
    Chriztian Steinmeier
    0

    Hi Fuji,

    You need to remove the /umbracoFile from the apply-templates line - the template matches the PhotoGallery item, remember?

    <xsl:apply-templates select="$media//Folder[@id = current()/galleryPicker]/PhotoGallery[1]" />

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 11, 2012 @ 19:03
    Fuji Kusaka
    0

    Still nothing showing up.

    I did try to display the  value of the picker "galleryPicker" and its returning the correct Media Folder name. 

    But no image is being output.

     <xsl:apply-templates select="$media//Folder[@id = current()/galleryPicker]/PhotoGallery[1]" />
  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 11, 2012 @ 20:08
    Fuji Kusaka
    0

    I try something like this

    <xsl:variable name="topFolderId" select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]" />    
    <xsl:variable name="media" select="umbraco.library:GetMedia($topFolderId, true())" />
        
    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
      
      <li>
          <!-- Show the first image in the folder picked by the Media Picker property on currentPage -->
       <xsl:value-of select="$media/PhotoGallery[1]"/>
      </li>               
      </xsl:for-each>
    </ul>
    </xsl:template>
        
        <!-- Template for the image -->
    <xsl:template match="galleryPicker">
      <img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" alt="{@nodeName}" />
    </xsl:template>

    From the code above am getting the right Node Name Links display all the links of the child nodes underneath. However still no images showing but i tried to display 

    <xsl:value-of select="$media/PhotoGallery[1]"/>

    And getting the same output for all child nodes

    • 2011
      /media/7130/_MG_0041_LR.jpg80053458827jpg
    • 2012
      /media/7130/_MG_0041_LR.jpg80053458827jpg
  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 12, 2012 @ 06:03
    Fuji Kusaka
    0

    Hi Chriztian,

    I finally  did something else and it works. Here is how my xslt looks like

    <ul>
    <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">  
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>  
       <li>
          <href="{umbraco.library:NiceUrl(@id)}">
        <xsl:call-template name="test"/>
         </a>
      </li
      </xsl:for-each>     
    </ul>
    </xsl:template>
        
         <xsl:template name="test">
           <xsl:variable name="mediapickerproperty" select="./galleryPicker"/>    
         <xsl:if test="$mediapickerproperty &gt; 0">  
          <xsl:for-each select="umbraco.library:GetMedia($mediapickerproperty, 1)/PhotoGallery[1]">
                       <img src="{umbraco.library:Replace(umbraco.library:GetMedia(@id, 0)/umbracoFile, '.', '_Thumbnail.')}"/>
      </xsl:for-each>    
         </xsl:if>    
        </xsl:template>

     

    Thanks for your help though, if you have a better way around most welcome.

     

    //fuji

  • 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