Copied to clipboard

Flag this post as spam?

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


  • Arnim Anhut 137 posts 148 karma points
    Dec 30, 2013 @ 18:57
    Arnim Anhut
    0

    How to use "locallink" in a razor-template (7.0.1)

    Hello,

    I just can't figure out how to use the old <...href='/{locallink:1071}'...> in a template using razor. I want to "hardlink" some stuff like copyright just inside the template but of course using locallink-mimik and not directly linking on the url.

    What syntax do I have to use?

     

    Thanx! Arnim.

  • Comment author was deleted

    Dec 30, 2013 @ 20:12

    You could try something like this:

     

    <a href='@Umbraco.TypedContent(1071).Url'>foobar</a>
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 30, 2013 @ 20:31
    Jeavon Leopold
    100

    So many ways to skin this cat, here's another option:

    <a href="@Umbraco.NiceUrl(1071)">foobar</a>
    
  • Comment author was deleted

    Dec 30, 2013 @ 20:35

    @Jeavon, nice.  I didn't know that was even an option.

  • Charles Afford 1163 posts 1709 karma points
    Dec 30, 2013 @ 21:17
    Charles Afford
    0

    I would be very worried hard coding a Node id in there.  Charlie :)

  • Arnim Anhut 137 posts 148 karma points
    Dec 31, 2013 @ 15:49
    Arnim Anhut
    0

    @Charlie: Why? Isn't it much better than hard coding a url?

    If I want links (like contact, copyright, search,... ) on every page - isn't that the only solution?

    @Kevin, Jeavon: Thanx a lot - work like a charm! Marking Jeavons, cause its more "obvious".

    Thanx for all your fast replies!

  • Comment author was deleted

    Dec 31, 2013 @ 15:56

    What Charlie probably means is that hardcoding an ID is not super portable if you have a staging/production setup.  They could potentially become out of sync (different ID on each server).  The chances are pretty low but the better way would be to navigate the tree structure and find a 'copyright' doctype or something like that.  That way it's agnostic to whatever ID it ends up with.

    It's a matter of taste, style and requirements.

    Possible ID-free alternative (not tested of course):

    <a href="@Model.Ancestor(1).Siblings().Where(x => x.ContentTypeAlias = "copyrightPage").FirstOrDefault().Url">Blah</a>
  • Charles Afford 1163 posts 1709 karma points
    Jan 02, 2014 @ 21:47
    Charles Afford
    0

    Kevin, yes exaclty and it can change.  You should not really just have a hard link.  If its content within Umbraco then it should come from Umbraco and be allowed some scope for change with out breaking code.

  • Charles Afford 1163 posts 1709 karma points
    Jan 02, 2014 @ 21:48
    Charles Afford
    0

    sorry for my late reply Amim

Please Sign in or register to post replies

Write your reply to:

Draft