Copied to clipboard

Flag this post as spam?

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


  • Manasa 80 posts 201 karma points
    Jun 16, 2015 @ 09:51
    Manasa
    0

    to fetch node url based on node id

    Hi,

    I have something like this:

    @siteURL/[email protected]

    This provides me a link something like : http://localhost/?p=1234

    On selecting this url and placing in address bar it should redirect to the page content.

    Ex: if 1234 is node id for home page, it should redirect to home page. How can I make this work like I expected?

    Thanks.

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jun 18, 2015 @ 10:58
    Mike Chambers
    0

    A razor macro should do for you added to your master template.

    @{Response.Redirect(Library.NodeById(Int.TryParse(Request.QueryString["p"])).url);}

    NB untested and you will need to add all the usual errortrapping like ensure p is an integer and corresponds to a published node etc..

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jun 18, 2015 @ 11:08
    Mike Chambers
    1

    Actually didn't notice U7

    Library.NodeById is deprecated...

    so you can use

    Umbraco.TypedContent(1234).Url

    instead [https://our.umbraco.org/documentation/Reference/Templating/Mvc/querying]

  • Manasa 80 posts 201 karma points
    Jun 18, 2015 @ 13:11
    Manasa
    0

    Thanks Mike.

    I have a doubt. I have a template where

    this is inside guid tag.

    The above provides me: sitename/1234.

    When i copy paste this it shows me correct page but with url as sitename/1234. Is there a way where i can change 1234 the id to url of the page?

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft