Media section: Display first published child node preview image
I have a macro linking to the media section. My mediatype has a true/false property "published", so I can publish and unpublish the media item. Hiding it from the macro by unpublishing it.
My macro lists all the media items with the media folder, and displays the first items preview image, as the preview image for the macro container on the front end.
However, if the first media item is "unpublished" then no preview image is displayed.
I need help, so that the first "published" media item within the list, has it's preview image displayed.
My current code only displays the first item in the list, and unfortunately if the first item is "unpublished" then no preview image is displayed on the front end. I need it to check through the list of items and find the first "published" media item and display it's preview image.
Your problem is caused by the outermost xsl:if - it takes the first item, regardless of the child AssetVersion's published property...
What is the context for the outermost xsl:if ? You need to perform a test there somehow, but which one, depends on how your structure looks; what's the name of the nodes that contain AssetVersion items?
The name of the node that contains the "AssetVersion" is "Asset", which has a parent folder "AssetsFolder". I link to the "AssetsFolder" and it lists all the "Asset" media items, and each "Asset" contains an "AssetVersion".
The "AssetVersion" has the "published" property type. If the "AssetVersion" is "unpublished" it doesn't display in the macro.
So I need my XSLT to first check all the items in the "AssetsFolder" then find the first "published" "AssetVersion" and display it's preview image.
Media section: Display first published child node preview image
I have a macro linking to the media section. My mediatype has a true/false property "published", so I can publish and unpublish the media item. Hiding it from the macro by unpublishing it.
My macro lists all the media items with the media folder, and displays the first items preview image, as the preview image for the macro container on the front end.
However, if the first media item is "unpublished" then no preview image is displayed.
I need help, so that the first "published" media item within the list, has it's preview image displayed.
My current code only displays the first item in the list, and unfortunately if the first item is "unpublished" then no preview image is displayed on the front end. I need it to check through the list of items and find the first "published" media item and display it's preview image.
Cheers, JV.
Hi JV,
Your problem is caused by the outermost xsl:if - it takes the first item, regardless of the child AssetVersion's published property...
What is the context for the outermost xsl:if ? You need to perform a test there somehow, but which one, depends on how your structure looks; what's the name of the nodes that contain AssetVersion items?
/Chriztian
Hi Chriztian,
The name of the node that contains the "AssetVersion" is "Asset", which has a parent folder "AssetsFolder".
I link to the "AssetsFolder" and it lists all the "Asset" media items, and each "Asset" contains an "AssetVersion".
The "AssetVersion" has the "published" property type. If the "AssetVersion" is "unpublished" it doesn't display in the macro.
So I need my XSLT to first check all the items in the "AssetsFolder" then find the first "published" "AssetVersion" and display it's preview image.
Here's a snippet of my XSLT:
Hi JV,
Great - here's how I would approach it - feel free to ask about any specifics, if you like:
/Chriztian
is working on a reply...