Hello, I am trying to get to work a tagging system for the images in the media section. I added a multiple dropdown list as part of the Image datatype, and I have previously filled the multiple dropdown list with prevalues.
I have been trying to loop all the images in a particular sub-folder in the media section and to check if the selected prevalues are matching the ones set in the doc type.
Here is the code I have borrowed from here and some good ideas from here and here
So far I just want to loop through all the images in the selected subfolder and list the matching prevalues. But I get a error on this one:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<!-- MAIN TEMPLATE --> <xsl:template match="/"> <!-- Variable with the selected media folder ID --> <xsl:variable name="mediaFolderID" select="$currentPage/data[@alias='SelectedFolder']"/>
<!-- Call template generates the HTML for the images--> <xsl:call-template name="LoopThroughImagesInFolder"> <xsl:with-param name="mediaFolderID"> <xsl:value-of select="$mediaFolderID"/> </xsl:with-param> </xsl:call-template>
</xsl:template>
<!-- LOOP THROUGH IMAGES IN FOLDER TEMPLATE --> <xsl:template name="LoopThroughImagesInFolder"> <!-- Parameter with a media folder ID --> <xsl:param name="mediaFolderID"/>
<!-- Check that you really have an ID --> <!-- Without this test the script can fail --> <xsl:if test="$mediaFolderID > 0">
<!-- Get the media node using the ID --> <xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, 1)" />
<!-- Check if the folder contains any child nodes --> <xsl:if test="count($images/node) > 0">; <!-- Start iterating the child nodes --> <xsl:for-each select="$images/node">
<xsl:choose> <!-- Is it an image? Please note that this only works if your images have the @nodeTypeAlias "Image". If you have called it something else, you need to replace the name. --> <xsl:when test="string(./@nodeTypeAlias) = 'Image'"> <!-- Print the image code --> <ul> <xsl:for-each select="umbraco.library:GetPreValues($currentPage)//preValues"> <li> <a href="#"> <xsl:value-of select="." /> </a> </li> </xsl:for-each> </ul> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:if> </xsl:if>
</xsl:template> </xsl:stylesheet>
You cannot retrieve XML for nodes in the Media section with the GetXmlNodeById() function - You should use the GetMedia() function for that, and send 'true' as the second argument to signal that you want the contents of a folder:
Get Dropdown Multiple Selected Items and Compare
Hello, I am trying to get to work a tagging system for the images in the media section. I added a multiple dropdown list as part of the Image datatype, and I have previously filled the multiple dropdown list with prevalues.
I have been trying to loop all the images in a particular sub-folder in the media section and to check if the selected prevalues are matching the ones set in the doc type.
Here is the code I have borrowed from here and some good ideas from here and here
So far I just want to loop through all the images in the selected subfolder and list the matching prevalues. But I get a error on this one:
Sorry, so far I just want to list all the values selected, not to compare them to anything, but I can't seem to get it to work.
Alright, trying a different approach. Based on this one.
I created a new datatype named tags which renders a checkbox list control with some prevalues inserted.
then modified the "Image" media type and added the tags datatype.
Then on some random template I inserted a macro that calls the following xslt:
But this doesn’t work, the <p>Do Something</p> paragraph never shows up, the 1537 node refers to a media folder under which are all the images.
Hi Antonio,
You cannot retrieve XML for nodes in the Media section with the GetXmlNodeById() function - You should use the GetMedia() function for that, and send 'true' as the second argument to signal that you want the contents of a folder:
- Lets hear how that works,
/Chriztian
.. aaand then I just forgot to include the 'true' part I wrote about :-)
/Chriztian
is working on a reply...