I have the following structure in my media section:
Ford
Mustang
mustang.png
Cadillac
Escalade
escalade.png
I have a model that holds the model and make of a vehicle. When I render a page, I pass it this model. I want to to be able to show the image from my media section that corresponds to the model data passed in, so if I passed in Escalade, I want to grab the image from the Escalade folder.
I have seen examples of getting the image by id, but I want to know if there is a way I can grab images from folders by the name.
I think the easiest way is to add a mediapicker to your page and let the editors select a picture. This way you don't need to query the entire media library for a matching image.
Access image from media section at runtime?
Hello,
I have the following structure in my media section:
Ford
Cadillac
I have a model that holds the model and make of a vehicle. When I render a page, I pass it this model. I want to to be able to show the image from my media section that corresponds to the model data passed in, so if I passed in Escalade, I want to grab the image from the Escalade folder.
I have seen examples of getting the image by id, but I want to know if there is a way I can grab images from folders by the name.
Thanks
I think the easiest way is to add a mediapicker to your page and let the editors select a picture. This way you don't need to query the entire media library for a matching image.
Dave
Dave,
Can you clarify? So if I have a root folder called product images, I can add this folder to a product page and on that page, grab the image I want?
How would I do this with razor syntax if I had something like:
Should I then add the Product Images to my Product page after I added a Media Picker property on the Product document type?
Let's say I wanted to grab the image from the nested folder in razor if my folder alias was productImages?
Thanks for the help, Saied
If you add a media picker datatype to your document type, and make sure you check "Pick multiple items"
You can then pick multiple images.
You should then be able to show the picked images like this
(code taken from this post)
How would I modify the code if instead of allowing the user to pick multiple images, they would just pick a folder?
Then I would just get the images from the folder.
Try this: https://our.umbraco.org/forum/developers/razor/44010-Display-images-from-media-folders#comment-158525
is working on a reply...