This will be a dumb question, but what is the URL helper? And how do I implement the code you provided? All customizations I have done thus far have been limited to template editing. I have not had to define variables/etc.
I tried adding your variable to the top @{ } section, then using @Url.GetAbsoluteMediaUrl(mediaItem) within the template, but there were parsing errors. It says 'System.Web.Mvc.UrlHelper' has no applicable method named 'GetAbsoluteMediaUrl'
I believe your var declaration is missing a closing parenthesis, by the way.
What is the easiest way, then, to set up an if/else that uses a default image URL if #postImage is null? Don't want the page to break when an image doesn't exist.
Other option, although it adds more code, is to go down the MVC track and get the image in your controller, setting a default value if nothing is defined. Always good to separate concerns where it makes sense to do so.
That way, in your view, you can simply render the image from the your model with full confidence that the image will always have a value.
How to Generate Full Media Picker URL?
How can I change this from showing the Media Picker path to the full URL?
That outputs /media/1038/image.jpg, but I need to instead output https://www.example.com/media/1038/image.jpg
I have tried editing the original code but can't figure it out. Do I need to somehow use insertBefore?
This is all code I am looking to add to a template file. Please be detailed with your instructions; I am still getting familiar with Umbraco.
Second, I would like to have a fallback image if #postImage doesn't exist (so the page doesn't break). Any help will be much appreciated.
Hi NK
You can get the full url by using
GetAbsoluteMediaUrl
on the Url helper, like so:That should do the trick ☺️
All the best
Rune
Hi Rune,
This will be a dumb question, but what is the URL helper? And how do I implement the code you provided? All customizations I have done thus far have been limited to template editing. I have not had to define variables/etc.
I tried adding your variable to the top @{ } section, then using @Url.GetAbsoluteMediaUrl(mediaItem) within the template, but there were parsing errors. It says 'System.Web.Mvc.UrlHelper' has no applicable method named 'GetAbsoluteMediaUrl'
I believe your var declaration is missing a closing parenthesis, by the way.
Thank you.
Hi NK
You can full url by using this little snippet of code below.
Best,
/Dennis
That did it. Thank you. Quick follow-up question:
What is the easiest way, then, to set up an if/else that uses a default image URL if #postImage is null? Don't want the page to break when an image doesn't exist.
Hi NK,
You can do it like this.
Remember to change the default image URL if postImage is null
Hope this helps,
/Dennis
Other option, although it adds more code, is to go down the MVC track and get the image in your controller, setting a default value if nothing is defined. Always good to separate concerns where it makes sense to do so.
That way, in your view, you can simply render the image from the your model with full confidence that the image will always have a value.
I am not getting your Question you want to pick complete media files and for that you want a Query than it is pretty simple
This will get all media files list from media section.
Not what I asked, but thanks.
is working on a reply...