Copied to clipboard

Flag this post as spam?

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


  • Anders 27 posts 47 karma points
    Sep 10, 2009 @ 18:57
    Anders
    0

    How to customize niceurl

    hello,

    I have now made a umbraco site with url's like /da/frontpage.

    How can i set the function "Niceurl" to se a / after the link automaticly?

    Regards Anders

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 10, 2009 @ 19:27
    Lee Kelleher
    0

    Hi Anders,

    There are a couple of ways to do that.

    In XSLT, you could use:

    <xsl:value-of select="concat(umbraco.library:NiceUrl(@id), '/')" />

    or in .NET code, you could create your own wrapper for the method:

    public static String MyNiceUrl(Int32 nodeId)
    {
        return String.Concat(umbraco.library.NiceUrl(nodeId), "/");
    }

     

    Let me know how it goes.

    Cheers,

    - Lee

  • Anders 27 posts 47 karma points
    Sep 10, 2009 @ 21:23
    Anders
    0

    I would like to edit the niceurl function, so it's allso work in the editor.? Is that possible?

  • Chris Koiak 700 posts 2626 karma points
    Sep 10, 2009 @ 22:16
    Chris Koiak
    2

    Hi Anders,

    What doesn't work in the editor (tinyMCE)?

    If you mean changing the url's of the inserted internal links (e.g. {localLink:1234}) then I can see that this would be more tricky.

    The way it works is this: Once the html for the page is about to be rendered to the response stream (default.aspx.cs - Render()) a call is made to template.ParseInternalLinks(). This changes the localLink syntax to the correct url.

    So either you can put your own default page in place, extending the one that's there and change this method. OR. you can change the way you are outputting the RTE generated content and replace the localLink:1234 text at this point.

    I'd go with the latter suggestion. So rather than

    <xsl:value-of select="$currentPage/data[@alias='bodyText']"/>

    You would have something like

    <xsl:value-of select="your.library:ParseInternalLinks($currentPage/data[@alias='bodyText'])"/>

     

    The current Parse method is this

      public static string ParseInternalLinks(string pageContents)
    {
    // Parse internal links
    MatchCollection tags = Regex.Matches(pageContents, @"href=""[/]?(?:\{|\%7B)localLink:([0-9]+)(?:\}|\%7D)", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
    foreach (Match tag in tags)
    if (tag.Groups.Count > 0)
    {
    string id = tag.Groups[1].Value; //.Remove(tag.Groups[1].Value.Length - 1, 1);
    string newLink = library.NiceUrl(int.Parse(id));
    pageContents = pageContents.Replace(tag.Value.ToString(), "href=\"" + newLink);
    }
    return pageContents;
    }

    you just need to create the xslt extension, copy in the code above and modify the NiceUrl call as you wish.

    Enjoy,

    Chris

  • Anders 27 posts 47 karma points
    Sep 11, 2009 @ 13:30
    Anders
    0

    Thanks for that. That would say that i could make the links to wath i wish to fx /page(id).aspx and so on?

    Regards Anders

  • Anders 27 posts 47 karma points
    Sep 11, 2009 @ 13:36
    Anders
    0

    And where is the .cs'files?

  • Chris Koiak 700 posts 2626 karma points
    Sep 11, 2009 @ 13:37
    Chris Koiak
    0

    Sorry Anders, I don't follow what you're asking. Can you expand?

    The solution I posted should allow you to change the output URL to any structure you wish.

  • Chris Koiak 700 posts 2626 karma points
    Sep 11, 2009 @ 13:38
    Chris Koiak
    0

    You would need to implement this solution yourself (writing your own C# and xslt extension).

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 11, 2009 @ 14:02
    Dirk De Grave
    0

    Can't you just do this using some juicy jquery that parses all a tags and adds a trailing slash? No need for core code modifications?

     

    Cheers,

    /Dirk

  • Chris Koiak 700 posts 2626 karma points
    Sep 11, 2009 @ 14:50
    Chris Koiak
    0

    Think about accessibility and search engines... javascript would need to be ruled out for both.

    If the localLink parsing happens via an xsltExtension then there's no need for core code modifications.

    On a side note - The parsing and loading of macros could also be brought foward into the xslt processing stages... therefore avoiding situations like http://our.umbraco.org/forum/templating/templates-and-document-types/4059-Including-user-control-in-rendered-list-of-eg-expo-boxes-or-news

     

Please Sign in or register to post replies

Write your reply to:

Draft