Hello everybody, i'm very new to Umbraco, and you'll soon know why. Here's my dilemma:
I'm creating an Umbraco with multiple sites
I want to build a Document Type I can use EVERYWHERE
I need to be able to get a media URL from that document type by a property ALIAS name, not a media ID because I need to use this code EVERYWHERE
As far as I understand, I get the media id after i create an instance of that document type within the properties tab, and each instance is a different media id. Am I correct?
so the question: How to get media url by property alias? like this:
var url - umbraco.GetMedia("backgroundImage").Url;
Please help!! or, point me to some good reading to I can figure it out myself.
Thanks Dennis, but I read this article already, and I tried these methods. I'm simple doing something wrong, or I created page incorrectly. please read the response I gave to Marc, and I has all the details I can give.
is your backgroundImage a Media Picker for a single item ?
If so then Umbraco stores the Id of the picked Media as the value of 'backgroundImage', on your content object
and then you can use something like this to turn the id into a url
(strongly typed)
var backgroundUrl = String.Empty;
var backgroundImage = Umbraco.TypedMedia(Model.Content.GetPropertyValue<int>("backgroundImage"));
if (backgroundImage != null){
backgroundUrl = backgroundImage.Url;
}
or dynamic:
var backgroundImageId = CurrentPage.backgroundImage;
var backgroundImage = Umbraco.Media(backgroundImageId);
var backgroundImageUrl = backgroundImage.Url;
How to get media url by property alias?
Hello everybody, i'm very new to Umbraco, and you'll soon know why. Here's my dilemma:
As far as I understand, I get the media id after i create an instance of that document type within the properties tab, and each instance is a different media id. Am I correct?
so the question: How to get media url by property alias? like this:
var url - umbraco.GetMedia("backgroundImage").Url;
Please help!! or, point me to some good reading to I can figure it out myself.
Thanks.
Hi Joseph and welcome to our.
Try to have a look at hos documentation.
https://our.umbraco.org/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker
Hope this helps,
/Dennis
Thanks Dennis, but I read this article already, and I tried these methods. I'm simple doing something wrong, or I created page incorrectly. please read the response I gave to Marc, and I has all the details I can give.
Thanks again
Hi Joseph
is your backgroundImage a Media Picker for a single item ?
If so then Umbraco stores the Id of the picked Media as the value of 'backgroundImage', on your content object
and then you can use something like this to turn the id into a url
(strongly typed)
or dynamic:
to get the Url of an image in any template
see: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/media-picker
for multiple picked images
or If you are using the ImageCropper:
https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/image-cropper
(which also has an overload for property alias)
Thanks for the response Marc.
Well, I tried both methods, and i'm still not getting anything back. Here's my view/template code:
Here's the view code:
Here's the Document Type
Here's the instance of the document type:
I'm simply not seeing any value when I inspect the element:
Hopefully this is enough information for you. Any help would be appreciated. If you want my code files, I'll be happy to email them to you.
Thanks!
Could you output the Name of the current page? Do something like @Model.Content.Name
Based on your code. 1) If you are browsing the url /joeyesquibel.com/Header/ , it should show the image a aspected.
2) However if you are browsing the url /joeyesquibel.com/ , It will not show the image because (currentpage) does not have "backgroundImage" property.
I need to do something like @Mode.Content.Chilldren().FirstOrDefault(x=>x.Name.Equal("Header")).GetPropertyValue
I have not tested the code.
Jivan,
I believe you're right. Here's the result:
The main page wouldn't have the background image, but the child would. Here's my working code:
Thanks for your time everybody.
is working on a reply...