I have a directory/node within my media library called Forms and a list of PDFs within. Is there an easy way of retrieving all items beneath this node with or without the ID of this node (preferrably without)? I've seen other examples of XSLT using the media library but I can't seem to get them to work.
One thing I don't understand is why I need to pass $currentPage into the GetMedia method. This is frustrating me, because I've done all sorts of fancy magic with XSLT and the content nodes, but I can't get something as simple as a list of files from the media lib to work.
I was hoping something like umbraco.library.GetAllMedia()//*[alias='Forms']//* would work, but no dice.
If you use library.GetMedia(folderId, true) you will get the an xml file with the folder and all it's children. You can do an xpath on that to get all the pdf's you need.
Currently I'm developing a new media picker which can select multiple items in 1 picker. This way instead of retrieving all files from a folder I can just select all the files I need with the media picker.
1160 is the ID of the folder I'm targeting. This ID can be seen in the Media section in the Properties tab for that folder. I'm assuming that Using 1 (synonymous for true in your example above) just tells the GetMedia function to grab the tree beneath recursively?
<xsl:for-each select="$mediaNode/Form" >
I've called my custom media type Form which is why I'm selecting $mediaNode/Form in the XPath. What really helped me with determining what XPath to use was the commented-out line:
<!-- <xsl:copy-of select="$mediaNode" />-->
This dumpped the Raw XML content of the node I selected to the page. Don't view using FireBug (if you use Firefox) because it mangles the structure. You'll have to view page source to get the proper structure. Mine, for example, using my custom Form type displayed:
Glad you've figured it out :). If you want to have the media xml readable in your umbraco.config you can also use the new media picker I'm working on. This can store the complete media xml instead of just the id. If you give me your e-mail I can send you a Release Candidate.
Retrieving a list of PDFs from the media library
I have a directory/node within my media library called Forms and a list of PDFs within. Is there an easy way of retrieving all items beneath this node with or without the ID of this node (preferrably without)? I've seen other examples of XSLT using the media library but I can't seem to get them to work.
One thing I don't understand is why I need to pass $currentPage into the GetMedia method. This is frustrating me, because I've done all sorts of fancy magic with XSLT and the content nodes, but I can't get something as simple as a list of files from the media lib to work.
I was hoping something like umbraco.library.GetAllMedia()//*[alias='Forms']//* would work, but no dice.
I'm having the same problem, I'm also looking for a way to get all documents from a folder in the medialibrary
Anthony
If you use library.GetMedia(folderId, true) you will get the an xml file with the folder and all it's children. You can do an xpath on that to get all the pdf's you need.
Currently I'm developing a new media picker which can select multiple items in 1 picker. This way instead of retrieving all files from a folder I can just select all the files I need with the media picker.
Jeroen
Thanks Jeroen,
I've got it working:
1160 is the ID of the folder I'm targeting. This ID can be seen in the Media section in the Properties tab for that folder. I'm assuming that Using 1 (synonymous for true in your example above) just tells the GetMedia function to grab the tree beneath recursively?
I've called my custom media type Form which is why I'm selecting $mediaNode/Form in the XPath. What really helped me with determining what XPath to use was the commented-out line:
This dumpped the Raw XML content of the node I selected to the page. Don't view using FireBug (if you use Firefox) because it mangles the structure. You'll have to view page source to get the proper structure. Mine, for example, using my custom Form type displayed:
<Folder id="1160" version="48bd637a-fd43-4b43-a097-ee8d541ef2e4" parentID="-1" level="1" writerID="0" nodeType="1031" template="0" sortOrder="55" createDate="2011-01-11T15:12:02" updateDate="2011-01-11T15:12:08" nodeName="Forms" urlName="forms" writerName="Administrator" nodeTypeAlias="Folder" path="-1,1160">
<contents />
<Form id="1161" version="270cc546-e201-469a-a88c-49b21f42a72f" parentID="1160" level="2" writerID="0" nodeType="1159" template="0" sortOrder="1" createDate="2011-01-11T15:13:33" updateDate="2011-01-11T15:13:39" nodeName="1170" urlName="1170" writerName="Administrator" nodeTypeAlias="Form" path="-1,1160,1161">
<file>/media/1954/1170.pdf</file>
<formNumber>1170</formNumber>
<formNumberSuffix />
<title>Fund Facts</title>
<thumbnail>1097</thumbnail>
<description>Fund facts, yo</description>
<section>Insurance Forms,Insurance Marketing Materials</section>
<category>Savings & Retirement,Claims</category>
</Form>
<Form id="1164" version="add77864-91b2-402c-863a-933e85dca270" parentID="1160" level="2" writerID="0" nodeType="1159" template="0" sortOrder="2" createDate="2011-01-12T11:09:41" updateDate="2011-01-12T11:09:46" nodeName="422" urlName="422" writerName="Administrator" nodeTypeAlias="Form" path="-1,1160,1164">
<file>/media/1996/422.pdf</file>
<formNumber>422</formNumber>
<formNumberSuffix />
<title>Not sure. I was too lazy to look.</title>
<thumbnail />
<description></description>
<section>Insurance Forms,Insurance Marketing Materials</section>
<category>Savings & Retirement,Claims</category>
</Form>
</Folder>
A useful tool I found with this was the following site which prettified (indented) my XML to I could see it better:
http://xmlindent.com/
I hope this helps someone. It's so simple, but I spent way too long getting it to work.
Now of course, in my example I'm only printing out the path to the file on the screen. I did this for simplicity.
Glad you've figured it out :). If you want to have the media xml readable in your umbraco.config you can also use the new media picker I'm working on. This can store the complete media xml instead of just the id. If you give me your e-mail I can send you a Release Candidate.
Jeroen
Hi Philip,
I've released the Digibiz Advanced Media Picker 1.0: http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker. Now you don't need to select a folder anymore. You can simply select all the items in the media picker and order them :).
Jeroen
is working on a reply...