Copied to clipboard

Flag this post as spam?

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


  • René Andersen 238 posts 684 karma points
    Mar 26, 2015 @ 13:43
    René Andersen
    0

    Output NiceUrl instead of page ID

    Hi

    I have this code which outputs the page ID instead of the page name. I use the content picker to choose which page to link to.

    @{
    if (CurrentPage.HasValue("showcasePicker"))
    {
    var showcaseList = CurrentPage.showcasePicker.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
    var showcaseCollection = Umbraco.Content(showcaseList);

    foreach (var item in showcaseCollection)
    {
    <div class="col-sm-6 product-item">
    <div class="thumbnail-style thumbnail-kenburn">
    <a class="btn-more hover-effect" href="@item.showcaseLink">læs mere +</a>
    </div>
    </div>
    }
    }
    }

    I found this post:

    https://our.umbraco.org/forum/developers/razor/45195-Attempting-to-get-nice-url-from-Ultimate-Picker

    But I can't get it to work.

    // René

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 26, 2015 @ 13:47
    Jan Skovgaard
    0

    Hi René

    So @item.Url does not work? What happens if you try using it? Nothing gets rendered or you get an error?

    Have you ensured that the link is never empty? I'm thinking that perhaps some entries have a link and others don't?

    /Jan

  • René Andersen 238 posts 684 karma points
    Mar 26, 2015 @ 14:15
    René Andersen
    0

    Hi Jan

    If I just use @item.Url does not work because it links to a page that does not exist.

    I need to show the link that I have choosen with the content picker:

    @item.showcaseLink

    It works but the link is an ID like this - localhost:37598/1058/

    I want it to be localhost:37598/profilbeklaedning/

    I thought that I could use NiceUrl but as far as i know then it does not work with Umbraco 7.

    // René

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 26, 2015 @ 15:19
    Jan Skovgaard
    1

    Hi René

    It links to a page that does not exist? Not sure I get that...if it returns an id...then there must be a page? But is it because it's not a page but a content element? Sorry if I'm being slow here but just trying to understand the issue fully :)

    /Jan

  • Martin 114 posts 313 karma points
    Mar 26, 2015 @ 16:04
    Martin
    0

    Hi,

    Not sure if I understand the issue either but I experienced a similar situation some time ago. It may be a long-shot, but my problem was that I forgot to published the page.

  • René Andersen 238 posts 684 karma points
    Mar 26, 2015 @ 16:29
    René Andersen
    0

    Hi Jan

    That's okay I also find it difficult to explain correctly. :-)

    What I need is a internal link to a subpage. The internal link is choosen with the content picker.

    At the moment it works, but the link to the subpage is outputted with the page ID and I would like it to output the page name instead.

    Is that possible when using the content picker?

    // René

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 26, 2015 @ 16:36
    Jan Skovgaard
    100

    Hi René

    Ok, still not sure that your explanation makes sense - You will want the urlName and not the page name in the href, right? :) Huge difference. But think I get it now...

    Could you use the @Umbraco.Content() helper to feed the id into so you can get the url like...

    @Umbraco.Content(item.showcaseLink).Url - Does this make sense? And does it work?

    /Jan

  • René Andersen 238 posts 684 karma points
    Mar 26, 2015 @ 16:40
    René Andersen
    0

    Hi Jan

    Sorry....Yes it is the urlName I need.

    Your code works perfect.

    // René

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 26, 2015 @ 16:41
    Jan Skovgaard
    0

    Hi René

    No need to be sorry - I just get a bit confused :D

    Happy to be able to help and getting better at reading between the lines ;-)

    /Jan

  • René Andersen 238 posts 684 karma points
    Jul 06, 2015 @ 14:59
    René Andersen
    0

    Hi

    I am using Jan Skovgaard's code in new project and now it is not working. My code looks like this:

    @{
    var infoList = CurrentPage.infoBoxes.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
    var infoCollection = Umbraco.Content(infoList);
    foreach (var item in infoCollection)
    {
        <div class="col-sm-4 panel-item">
            <a class="panel panel-image" href="@Umbraco.Content(item.internalLink).Url">
                <div class="panel-icon">
                    <i class="fa fa-clock-o icon"></i>
                </div>
                <div class="panel-heading"><img class="img-responsive-sm" alt="..." width="768" height="300" src="@item.image" /></div>
                <div class="panel-body">
                    <h3 class="panel-title">@item.headline</h3>
                    <p>@item.teaserText</p>
                </div>
            </a>
        </div>
    }
    

    }

    Now I get this error message:

    The call is ambiguous between the following methods or properties: 'Umbraco.Web.UmbracoHelper.Content(params int[])' and 'Umbraco.Web.UmbracoHelper.Content(params string[])'

    What am I doing wrong?

    //René

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jul 06, 2015 @ 15:16
    Dennis Aaen
    1

    Hi René

    Have you considering use the helper method called NiceUrl, with this you should get what you are after.

    @Umbraco.NiceUrl(item.internalLink)
    

    If you have a case where you the full domain, there is a helper method for that as well. NiceUrlWithDomain.

     @Umbraco.NiceUrlWithDomain(item.internalLink)
    

    The documentation can be found here just search for NiceUrl. https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    Hope this helps,

    /Dennis

  • René Andersen 238 posts 684 karma points
    Jul 06, 2015 @ 15:19
    René Andersen
    0

    Hi Dennis

    I have followed your advice and that solved my problem. My code now looks like this:

    <a class="panel panel-image" href="@Umbraco.NiceUrl(item.internalLink)">
    

    Thank you!

    // René

Please Sign in or register to post replies

Write your reply to:

Draft