I have a list of books in a media library that I want to aggregate based on tags. A page will have a book filter key, each book has a list of tags. The list of books for the page will be retrieved by getting all books with a given tag. I dont see an override for GetMedia that gets a list of all of a given type. Does this not exists or am I not going a good job of googling?
I got this working. I can use GetMedia to get the parent folder, then loop the children. I guess I could also start from the root and filter with the select (which would be slower because all of the nodes get touched). I was looking for a convenient function that I could just drop in and use.
Just make sure you're aware of the performance hit when using GetMedia() recursively (2nd parameter = 'true'). It will hit the database for each media item found this way (and this may be more hits than you can imagine). Have a look at @Sebastiaan 's ( or @Cultiv 's) project which caches media items for later fast retrieval.
Just a note about that 2nd parameter, cause there's a really nasty trap there:
You will have to supply either 0 (zero, no quotes/apostrophes) or false(), or it will actually evaluate to true when passed to C#, because 'false' is just a string in XSLT, which is will return the XSLT boolean true() when converted to a boolean value...
loop over items in media library, then filter by tag
I have a list of books in a media library that I want to aggregate based on tags. A page will have a book filter key, each book has a list of tags. The list of books for the page will be retrieved by getting all books with a given tag. I dont see an override for GetMedia that gets a list of all of a given type. Does this not exists or am I not going a good job of googling?
Thanks!
-T
As far as I am aware there is not an override.
But you can easily filter through that data using XSLT, should be really simple.
I'm setting up a test Umbraco install to look at another issue tomorrow, so I'll try and have a look at this as-well.
/Laurie
I got this working. I can use GetMedia to get the parent folder, then loop the children. I guess I could also start from the root and filter with the select (which would be slower because all of the nodes get touched). I was looking for a convenient function that I could just drop in and use.
Thanks for the reply. I am all good now.
-T
Tommy,
Just make sure you're aware of the performance hit when using GetMedia() recursively (2nd parameter = 'true'). It will hit the database for each media item found this way (and this may be more hits than you can imagine). Have a look at @Sebastiaan 's ( or @Cultiv 's) project which caches media items for later fast retrieval.
Hope this helps.
Regards,
/Dirk
Just a note about that 2nd parameter, cause there's a really nasty trap there:
You will have to supply either 0 (zero, no quotes/apostrophes) or false(), or it will actually evaluate to true when passed to C#, because 'false' is just a string in XSLT, which is will return the XSLT boolean true() when converted to a boolean value...
/Chriztian
is working on a reply...