I'm trying to list all images in a folder and it is really driving me crazy. Hope someone of you can help.
I want to list all images in a folder, the folder should be chosen when inserting the Macro (so not defined in a document type, that's something that I got working but not what I'm looking for). So far so good: I created a macro with an xslt and added a parameter 'mediaFolder' with type 'mediaCurrent'. When inserting the Macro I can select the folder. Nice.
<xsl:param name="currentPage"/> <!-- This is our Macro Paramater with the alias of mediaFolder --> <xsl:param name="mediaFolder" select="/macro/mediaFolder" />
<!-- The value of mediaFolder is an XML snippet, where we need to select the id attribute from the XML node <node> --> <xsl:param name="mediaFolderID" select="$mediaFolder/node/@id" />
Ok, well that's probably because you're looking for a /node element, which does not exist in the current schema and is not what you get returned anyway :)
It looks to me that you have found some old XSLT that match the old XML schema, from version Umbraco 4.5, and later on there were implemented a new XML schema, which also have influence on how you should write your XSLT.
<xsl:param name="currentPage"/> <!-- This is our Macro Paramater with the alias of mediaFolder --> <xsl:param name="mediaFolder" select="/macro/mediaFolder" />
<!-- The value of mediaFolder is an XML snippet, where we need to select the id attribute from the XML node <node> --> <xsl:param name="mediaFolderID" select="$mediaFolder/@id" />
I just discovered I get nothing returned when I insert the macro in my template (where it should be). In my post above I inserted the Macro in a rich text editor in the 'content' section of the site. (The information I got was something like /media/22323/nameoftjepicture.jp1513211331..4556151jpg so it looked strange to me).
Which I understand from your post above, I should add
but when saving the XSLT I get 'Error occured System.OverflowException: Value was either too large or too small for an Int32.' When I replace $mediaFolder with a number, I can save. So I think the variable is still empty.
I saw when I insert the macro in the template, a property mediaFolder="1327" is added, 1327 is the ID of the selected folder. Maybe this is what I need to get?
Edit: I saw I didn't paste the code well, so insterted it.
Have a look at the link I posted and the example Dennis posted above as well.
The error you got is because the value is not known before runtime so to avoid seeing it (if you're editing the XSLT inside Umbraco) and in general you need to make sure that the variable has a value before passing it the GetMedia extension.
<xsl:if test="$files != ''"> <ul> <!-- For each XML node <node> where the nodeTypeAlias attribute = File --> <xsl:for-each select="$files/Image"> <li> <!-- On the current XML node <node> find the XML node <data> where the alias atribute = umbracoFile --> <!-- This is where the filepath to the file is stored --> <a href="{./umbracoFile}" class="external"> <img src="{./umbracoFile}" /> </a> </li> </xsl:for-each> </ul> </xsl:if> </xsl:if> </xsl:template> </xsl:stylesheet>
I can save now (and now I understand what you ment with you have to check if it exists, but didn't know xslt was going to check if I checked it). But still I get no 'Yipee'.
List images in a folder fails
Hello,
I'm trying to list all images in a folder and it is really driving me crazy. Hope someone of you can help.
I want to list all images in a folder, the folder should be chosen when inserting the Macro (so not defined in a document type, that's something that I got working but not what I'm looking for). So far so good: I created a macro with an xslt and added a parameter 'mediaFolder' with type 'mediaCurrent'. When inserting the Macro I can select the folder. Nice.
In my XSLT I have the following:
But in never get the 'Yipee' ! Somebody who can explain this?
Is use Umbraco V4.11.3
I found this tutorial which I try to follow: http://our.umbraco.org/wiki/reference/code-snippets/listfilesfrommediafolderxslt
Hi Robin
What do you see if you write out the content of your $mediaFolder variable? Does it contain anything?
/Jan
Hi Jan,
$mediaFolder does give a value, but $mediaFolderID doesn't
The check should be:
<xsl:if test="$mediaFolder > 0">
<p>Yipee</p>
</xsl:if>
and if I add:
I get a value, but if I add:
Nothing returns
Hi Robin
Ok, well that's probably because you're looking for a /node element, which does not exist in the current schema and is not what you get returned anyway :)
You need to feed the id to the GetMedia extension - Have a look at this http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
Hope this helps
/Jan
Hi Robin,
It looks to me that you have found some old XSLT that match the old XML schema, from version Umbraco 4.5, and later on there were implemented a new XML schema, which also have influence on how you should write your XSLT.
What if you do something like this:
Here a some documentation on the difference between the new and the old XML schema.
http://our.umbraco.org/wiki/reference/xslt/45-xml-schema
http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema
http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/no-more-@nodetypealias
Hope this helps,
/Dennis
Hi,
I just discovered I get nothing returned when I insert the macro in my template (where it should be). In my post above I inserted the Macro in a rich text editor in the 'content' section of the site. (The information I got was something like /media/22323/nameoftjepicture.jp1513211331..4556151jpg so it looked strange to me).
Which I understand from your post above, I should add
but when saving the XSLT I get 'Error occured System.OverflowException: Value was either too large or too small for an Int32.' When I replace $mediaFolder with a number, I can save. So I think the variable is still empty.
I saw when I insert the macro in the template, a property mediaFolder="1327" is added, 1327 is the ID of the selected folder. Maybe this is what I need to get?
Edit: I saw I didn't paste the code well, so insterted it.
Hi Robin
Yeah, that sounds right :)
Have a look at the link I posted and the example Dennis posted above as well.
The error you got is because the value is not known before runtime so to avoid seeing it (if you're editing the XSLT inside Umbraco) and in general you need to make sure that the variable has a value before passing it the GetMedia extension.
Hope this helps.
/Jan
Hi,
It still doesn't work.
I deleted the /node in my code, but nothing changed. Also when I just copy/paste the code from Dennis it gives nothing. The $mediaFolderID stays empty
Hi Robin
Aaah, well that's because he's doing something that won't work either it seems.
The below is copy pasted from the page I linked to.
In the $media variable the GetMedia extension is being used.
It returns the stuff you need to succeed - in your case it would look like this currently
Hope this works :)
/Jan
:(
I still got the same error, but if I change $currentpage/bannerImage to 7777 I can save.
Argh, sorry!
You need to place the variable inside the if statement. My bad!
Try this.
/Jan
Hi Robin,
With this snippet of code you should get the images from the folder that you have choosen when you added the macro into your template.
Hope this helps,
/Dennis
No problem,
I can save now (and now I understand what you ment with you have to check if it exists, but didn't know xslt was going to check if I checked it). But still I get no 'Yipee'.
Hi Dennis,
Fantastic!! It works like a charm. Thanks a lot. I have a look now why it works :)
Also thanks to Jan for his time and effort!
Hi Robin,
You are welcome, can you please mark this as solved, so other people that came across the post can go directly to the solution that works for you.
/Dennis
Hi Robin
You're welcome :)
/Jan
is working on a reply...