Accessing images in the Media section in xsl without media picker.
Here is my problem:
I have a document type which has a text string, that has a comma separated list of all the images that need to be displayed on the page.
I see those images in the "Media" section of Umbraco under a new folder I created.
I dont have a media picker on the document type I created.
In xsl I am already parsing each image name from the comma separated string. Now using this how do I set the "src" attribute on an image tag inside xsl, to display the image. Or in other words, how do I access the images in the Media section, based on the image name, when I dont have a media picker.
Any help would be greatly appreciated. I did search this forum but couldnt find an answer. Thanks in advance
No I have one folder for all the images. Basically we dump all the pictures in one folder. On the page, we have a string that stores the comma separated list of all the images. Now when I parse through each member in the list, I need to find and display that image on the page.
I hope this makes sense. Please let me know if it doesnt.
So you have a comma separated string stored as value for a document property (For example: "test.jpg,test-1.jpg"), and those images are all stored in a folder in the media section? It's a bit of a pain I guess, as from an image name, it's pretty hard to find the path. Even though images are stored in the same folder in the media section, the individual images (their filename) don't have a reference to the 'media section' folder in which they reside.
test.jpg may be stored in folder /media/1234/test.jpg whereas test-1.jpg may be stored as /media/4567/test-1.jpg but there's nothing that ties those filenames to the folder you've created in the media section.
As a quick workaround, I'd store the image node id's in your document property, split the values (as it's a comma separated value), use GetMedia() function to get the filename path based on the media node id.
Other workaround would be to create a small xslt extension to 'search' for an image in the /media folder based on the image filename.
Still, I'd like to hear why you're not using media picker or the tree multi picker. You may get out of sync if someone uploads a new version of an image which does not have the same filename.
Here is the reason why we are not using a media picker/tree multi picker. Maybe you can point out the flaw and show us the correct path. We are displaying all images that come in an xml file, which we get from a different service. As of now, we are importing that xml file into umbraco using one of the available packages. I dont know how we could use a media picker to associate all these images, as the number of images vary.
Also could you please tell us how to implement the second idea? i.e how do I create and xslt to search for an image in the media folder based on the file name?
Ok, that's a viable reason for not using media pickers? Are those images also transferred from source to your target dir in the /media folder? How is that handled?
About implementing an xslt extension, here's an interesting read on how to build xslt extensions. In your case, you'd have to build a static function that accepts an string parameter (name of the pic file) and returns the complete path of the image.
I guess I gave in and added a media picker to the master content page. This media picker points to the parent image folder(the one I created) in the media section. This way I have access to all the media files in each of the child pages. Now after parsing through my comma separated list of image names, I choose the correct image and display it.
Thanks again for everybody's help regarding this issue.
Accessing images in the Media section in xsl without media picker.
Here is my problem:
I have a document type which has a text string, that has a comma separated list of all the images that need to be displayed on the page.
I see those images in the "Media" section of Umbraco under a new folder I created.
I dont have a media picker on the document type I created.
In xsl I am already parsing each image name from the comma separated string. Now using this how do I set the "src" attribute on an image tag inside xsl, to display the image. Or in other words, how do I access the images in the Media section, based on the image name, when I dont have a media picker.
Any help would be greatly appreciated. I did search this forum but couldnt find an answer. Thanks in advance
this is the code i have in there and it doesnt work
<xsl:if test="string-length($currentPage/ancestor-or-self::node/data [@alias='test.jpg']) > 0">
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($currentPage/ancestor-or-self::node/data [@alias='test.jpg'], 'false')/data [@alias = 'umbracoFile']"/>
</xsl:attribute>
</img>
</xsl:if>
I'm not sure, but I think you have not alias type 'test.jpg' in your datatype.
Do you have a folder of images for each page?
Thank you guys for your replies.
No I have one folder for all the images. Basically we dump all the pictures in one folder. On the page, we have a string that stores the comma separated list of all the images. Now when I parse through each member in the list, I need to find and display that image on the page.
I hope this makes sense. Please let me know if it doesnt.
can anyone help me on this? we are running out of time and ideas. thanks
Hi Vijay,
So you have a comma separated string stored as value for a document property (For example: "test.jpg,test-1.jpg"), and those images are all stored in a folder in the media section? It's a bit of a pain I guess, as from an image name, it's pretty hard to find the path. Even though images are stored in the same folder in the media section, the individual images (their filename) don't have a reference to the 'media section' folder in which they reside.
test.jpg may be stored in folder /media/1234/test.jpg whereas test-1.jpg may be stored as /media/4567/test-1.jpg but there's nothing that ties those filenames to the folder you've created in the media section.
As a quick workaround, I'd store the image node id's in your document property, split the values (as it's a comma separated value), use GetMedia() function to get the filename path based on the media node id.
Other workaround would be to create a small xslt extension to 'search' for an image in the /media folder based on the image filename.
Still, I'd like to hear why you're not using media picker or the tree multi picker. You may get out of sync if someone uploads a new version of an image which does not have the same filename.
Cheers,
/Dirk
Dirk, Thanks a bunch for replying.
Here is the reason why we are not using a media picker/tree multi picker. Maybe you can point out the flaw and show us the correct path. We are displaying all images that come in an xml file, which we get from a different service. As of now, we are importing that xml file into umbraco using one of the available packages. I dont know how we could use a media picker to associate all these images, as the number of images vary.
Also could you please tell us how to implement the second idea? i.e how do I create and xslt to search for an image in the media folder based on the file name?
Ok, that's a viable reason for not using media pickers? Are those images also transferred from source to your target dir in the /media folder? How is that handled?
About implementing an xslt extension, here's an interesting read on how to build xslt extensions. In your case, you'd have to build a static function that accepts an string parameter (name of the pic file) and returns the complete path of the image.
Let me know if still unclear.
Hope this helps.
Regards,
/Dirk
Dirk,
I guess I gave in and added a media picker to the master content page. This media picker points to the parent image folder(the one I created) in the media section. This way I have access to all the media files in each of the child pages. Now after parsing through my comma separated list of image names, I choose the correct image and display it.
Thanks again for everybody's help regarding this issue.
is working on a reply...