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>
<!-- The fun starts here --> <ul> <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <a 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.
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> <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()/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
<!-- The fun starts here --> <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: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
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??
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:
/Chriztian
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.
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.
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.:
/Chriztian
Nope still nothing is showing up. I also try to add some dummy text in the Template but nothing is showing up.
Hi Fuji,
You need to remove the /umbracoFile from the apply-templates line - the template matches the PhotoGallery item, remember?
/Chriztian
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.
I try something like this
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
And getting the same output for all child nodes
Hi Chriztian,
I finally did something else and it works. Here is how my xslt looks like
Thanks for your help though, if you have a better way around most welcome.
//fuji
is working on a reply...