Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Carlos Gómez 25 posts 55 karma points
    Feb 06, 2015 @ 05:08
    Carlos Gómez
    0

    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.

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 06, 2015 @ 05:28
    Jan Skovgaard
    0

    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

  • Carlos Gómez 25 posts 55 karma points
    Feb 06, 2015 @ 06:08
    Carlos Gómez
    0

    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.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 06, 2015 @ 07:18
    Jan Skovgaard
    0

    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

  • Carlos Gómez 25 posts 55 karma points
    Feb 06, 2015 @ 07:47
    Carlos Gómez
    0

    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.

  • Tobias Klika 101 posts 570 karma points c-trib
    Feb 06, 2015 @ 08:54
    Tobias Klika
    0

    Hi!

    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")).

    Bye Tobi

Please Sign in or register to post replies

Write your reply to:

Draft