Copied to clipboard

Flag this post as spam?

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


  • Chris Mahoney 235 posts 447 karma points
    May 08, 2015 @ 04:28
    Chris Mahoney
    0

    Preferred way to link to a page from template?

    Hi,

    I'm trying out Umbraco 7.2.4 and would like to know the best way to link to another page on my site from a template. In 4 and 6 I could do something like <a href="/{local Link:1234}"> (no space) and it'd link to the page with that ID, maintaining the link automatically as the page is moved or renamed. However, in 7, that doesn't work; it just copies the HTML verbatim instead of linking to the right page.

    I haven't been able to find any documentation around how to accomplish this in 7. Naturally I don't want to use the actual URL in case the target page is moved. What's the best way to do this?

    Thanks :)

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 08, 2015 @ 10:00
    Dennis Aaen
    2

    Hi Chris,

    The way you can do it is to use one of the Umbraco helpsers https://our.umbraco.org/DOCUMENTATION/Reference/Querying/UmbracoHelper/

    To do it in the dynamic Razor you could use:

    @Umbraco.Content(1234).Url

    For the strongly typed Razor you can use.

    @Umbraco.TypedContent(1234).Url

    Hope this helps,

    /Dennis

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 08, 2015 @ 10:21
    Jeavon Leopold
    102

    If you only want the URL you could use the NiceUrl method

    @Umbraco.NiceUrl(1234)
    

    Jeavon

  • Chris Mahoney 235 posts 447 karma points
    May 10, 2015 @ 22:07
    Chris Mahoney
    0

    Yes, NiceUrl works. Thanks for that. Going from 6 to 7 is proving "interesting"! :)

Please Sign in or register to post replies

Write your reply to:

Draft