Have you added a hostname to your website? If so it should return the whole url I believe. However it did not do this in older version where all you got was the path after the domain. But in newer versions you should get it all when a hostname has been set.
Well it might be because the NiceUrl method is being/has been deprecated in favor of the .Url method. So perhaps it's just better to always .Url from now on :)
You shouldn't use NiceUrl for nodes anymore. Just use the Url method in UmbracoHelper.
So type Umbraco.Url(yourId) instead of Umbraco.NiceUrl. You don't need to create IPublishedContent and get the URL there.
In your case it would be: Umbraco.Url(Model.Content.GetPropertyValue<int>("cstm1DireccionDestino")).
Trying to understand NiceUrl
hello...
In a document type I have a "content picker".
In the content page, I choose the content page I want to use.
In the Template I have this:
document.getElementById("btnCarrousel1").onclick = function () { location.href = "@Umbraco.NiceUrl(Int32.Parse(Umbraco.Field("cstm1DireccionDestino").ToString()))";};
When served the content, it is not returning the Url, but only the root path of the page.
I mean.... the app is located in www.domain.com/UmbracoApp/ but it is returning only "/UmbracoApp/" and not the name of the page.
I hardcoded the function in this way:
document.getElementById("btnCarrousel1").onclick = function () { location.href = "@Umbraco.NiceUrl(1112)";};
And it is returning the same, which confirms that it is not a problem of the function.
What am I missing?
Regards.
Hi Carlos
Have you added a hostname to your website? If so it should return the whole url I believe. However it did not do this in older version where all you got was the path after the domain. But in newer versions you should get it all when a hostname has been set.
What exact version of Umbraco 7 are you using?
/Jan
Hello Jan.
I hadn't set it... that is why it was returning "/subdir/" and that is it.
Now that you mentioned it, I set the hosts:
http://www.domain.com
and now it is returning: "https://www.domain.com/dir/"
But still missing the page name... it should be: https://www.domain.com/dir/PageName
...
Update:
Changed to this:
onclick="location.href = '@Umbraco.TypedContent(Model.Content.GetPropertyValue<int>("cstm1DireccionDestino")).Url'"
Now it works.
What is the difference? Shouldn't be working the firs one I was using?
Thanks.
Hi Carlos
Good to hear you got it working.
Well it might be because the NiceUrl method is being/has been deprecated in favor of the .Url method. So perhaps it's just better to always .Url from now on :)
/Jan
Excellent Jan, thanks a lot.
I am using the 7.2.2 version.
Wouldn't it be great to have more direct way to get the url, simmilar to the way we get the id that it doesn't have usually as much use as the url?
Regards and thanks for the following up.
Hi!
You shouldn't use NiceUrl for nodes anymore. Just use the Url method in UmbracoHelper.
So type
Umbraco.Url(yourId)
instead ofUmbraco.NiceUrl
. You don't need to create IPublishedContent and get the URL there.In your case it would be:
Umbraco.Url(Model.Content.GetPropertyValue<int>("cstm1DireccionDestino"))
.Bye Tobi
is working on a reply...