I'm having trouble using getMedia in 4.5. I have a content document "Home" which has child documents with alias "HomeSlideShowItem". Each child document has a "slideImage" which is a media picker. I want to loop through each child document and show the slide as an image. So, the content tree looks like:
Home
---Slide One (has a property alias "slideImage" of type Media Picker)
---Slide Two (has a property alias "slideImage" of type Media Picker)
And the umbraco.config xml file looks like the following. How can I access each slideImage within the child documents and display it as an image, in xslt and using getMedia? The output should look something like:
The real XSLT way to do this s to create a template slideImage element that fetches the mediaNode and outputs the image, then in your main template, just tell the processor to apply templates to the slideImage elements that has been filled:
Thanks very much for your sample code. Unfortunately, I don't get any results returned by the XSLT script when I replaced my code with yours. I'm guessing nothing is being matched. I also do not get any matches when I use "$currentPage/HomeSlideShowItem". I only get results when I use "$currentPage/*" but of course this gives me more than I want. Is there some change I should make to your sample code that I'm not aware of? How might I debug this?
If you're running this macro with "home" as $currentPage, you should indeed get something out, it looks like you're maybe on on of the HomeSlideShowItem pages - but fear not; we'll try to bulletproof it.
if you change the apply-templates instruction in the root template ("/") to this, you should hit the right noeds, no matter where you are (providing the layout you described above):
I think there was an additional problem with my installation-- it didn't make sense that I wasn't getting any template matches on the Home page with very simple xpath queries, so I deleted my home page content node and rebuilt it. I can't quite explain why this worked but after that simple xpath queries worked. I then used your code along with my own and some code from other forum posts to get the following working code.
Using getMedia in 4.5 in Xslt
Greetings all,
I'm having trouble using getMedia in 4.5. I have a content document "Home" which has child documents with alias "HomeSlideShowItem". Each child document has a "slideImage" which is a media picker. I want to loop through each child document and show the slide as an image. So, the content tree looks like:
Home
---Slide One (has a property alias "slideImage" of type Media Picker)
---Slide Two (has a property alias "slideImage" of type Media Picker)
And the umbraco.config xml file looks like the following. How can I access each slideImage within the child documents and display it as an image, in xslt and using getMedia? The output should look something like:
Thanks for your suggestions!
-NorthK
Hi NorthK,
The real XSLT way to do this s to create a template slideImage element that fetches the mediaNode and outputs the image, then in your main template, just tell the processor to apply templates to the slideImage elements that has been filled:
/Chriztian
Greetings Chriztian,
Thanks very much for your sample code. Unfortunately, I don't get any results returned by the XSLT script when I replaced my code with yours. I'm guessing nothing is being matched. I also do not get any matches when I use "$currentPage/HomeSlideShowItem". I only get results when I use "$currentPage/*" but of course this gives me more than I want. Is there some change I should make to your sample code that I'm not aware of? How might I debug this?
Thanks,
NorthK
Hi again,
If you're running this macro with "home" as $currentPage, you should indeed get something out, it looks like you're maybe on on of the HomeSlideShowItem pages - but fear not; we'll try to bulletproof it.
if you change the apply-templates instruction in the root template ("/") to this, you should hit the right noeds, no matter where you are (providing the layout you described above):
/Chriztian
Hi Chriztian,
I think there was an additional problem with my installation-- it didn't make sense that I wasn't getting any template matches on the Home page with very simple xpath queries, so I deleted my home page content node and rebuilt it. I can't quite explain why this worked but after that simple xpath queries worked. I then used your code along with my own and some code from other forum posts to get the following working code.
Thanks again for your help!
-NorthK
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:for-each select="$currentPage/HomeSlideShowItem">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia(number(slideImage), 0)"/>
<img src="{$mediaNode/umbracoFile}" width="{$mediaNode/umbracoWidth}" height="{$mediaNode/umbracoHeight}" alt="Web design work sample" />
</xsl:for-each>
</xsl:template>
is working on a reply...