I'm trying to build one macro that returns the path of one media library file. The name of the media is constructed inside the macro, depending on some params.
After having the name of the image I need to get the mediaId, so I can use inside the GetMedia function.
It's something that just won't work. Even if you'd write some xslt extension to iterate all media items, you may end up getting the wrong media item, as multiple media items can have the same name, and even the same filename... so it's a no-go imo.
Can you elaborate on your context for trying to get the id based on name of media item? Maybe other solutions may be more efficient...
I'm building one 1-1 multilingue site. This site has some images that contains labels. I want to switch the image to the approprieted language.
In my template, i choose the media in the default language than, depending on the selected language, I change the name of the image (All images are in the same folder) - Lets see the example:
I have this 3 images:
Media > Labels > label1
Media > Labels > label1_en
Media > Labels > label1_es
The first one is the default image, the others are the translated versions of the same label. I have the MediaID for the first image, but want to display the image, depending of the selected language (passed by querystring).
I use this code tho build the mediaName for the image I want to load, where mediaPropId is the ID of the default image:
I went the route of getting the folder of the image, and then go over all images to see if they are translated. (each folder only contains 20/30 images).
I come up with this code, but is still not working :(
Get media file by name
Hello,
I'm trying to build one macro that returns the path of one media library file. The name of the media is constructed inside the macro, depending on some params.
After having the name of the image I need to get the mediaId, so I can use inside the GetMedia function.
I can't get the mediaId having the name of the image.
I've tryed
If the image were in the Content section, the previous line would work. But in the Media section it doesn't work..
Nothing seems to work. Am i missing something? Is there another way to do this?
Thanks for your help
Hi Paulo
To get the name of the file you need to just ask for the @nodeName property.
You can get the image name by writing this
/Jan
Paulo,
It's something that just won't work. Even if you'd write some xslt extension to iterate all media items, you may end up getting the wrong media item, as multiple media items can have the same name, and even the same filename... so it's a no-go imo.
Can you elaborate on your context for trying to get the id based on name of media item? Maybe other solutions may be more efficient...
Cheers,
/Dirk
@Jan: that's exactly the point, he doesn't know the media id until he gets it based on the "name" (filename?) of the media item
Cheers,
/Dirk
Oh sorry, my bad! :-)
/Jan
Ok, this is the scenario I need to get the media.
I'm building one 1-1 multilingue site. This site has some images that contains labels. I want to switch the image to the approprieted language.
In my template, i choose the media in the default language than, depending on the selected language, I change the name of the image (All images are in the same folder) - Lets see the example:
I have this 3 images:
The first one is the default image, the others are the translated versions of the same label. I have the MediaID for the first image, but want to display the image, depending of the selected language (passed by querystring).
I use this code tho build the mediaName for the image I want to load, where mediaPropId is the ID of the default image:
So, refrasing the question, having one image (that we have the mediaId), can we get another image in the same folder with that image name?
Thanks again.
I went the route of getting the folder of the image, and then go over all images to see if they are translated. (each folder only contains 20/30 images).
I come up with this code, but is still not working :(
The result of $targetImage is always empty. Some lights?
Thanks in advanced.
I managed to fix this.
I had to do this changes:
In the GetImageTemplate, insted of
It should be:
And in the otherwise, insted of
It should be:
Whith this, i can get the right image.
Thanks to everybody for the help....
is working on a reply...