Copied to clipboard

Flag this post as spam?

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


  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Oct 09, 2009 @ 20:01
    Morten Bock
    0

    Overriding umbraco locallink parser

    Hi all

    I'm looking to override the way that umbraco parses the {locallink:1234} text that is created in RTE datatypes.

    So far, I can tell that they are parsed in the default.aspx pages Render() method.

    I can replace that with my own aspx page that inherits from umbraco.UmbracoDefault, but that means that I have to get the actual content from base.Render(), and if I do that, then the content has already been parsed.

    Have any of you done this successfully before, or do you have an idea on how to achieve this in a way that will not need me to modify the umbraco source?

    Thanks

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Oct 11, 2009 @ 19:29
    Morten Bock
    -1

    Ok, I think I solved this one.

    I created a my own default.aspx page, with the same attributes as the umbraco one.

    In my default.aspx.cs file, I inherit from the UmbracoDefault page.

    public partial class _Default : umbraco.UmbracoDefault
    {
        protected override void Render(HtmlTextWriter writer)
        {
            TextWriter tempWriter = new StringWriter();
            base.RenderChildren(new HtmlTextWriter(tempWriter));
            string pageContents = tempWriter.ToString();
            //Do the string magic you want...
            pageContents = pageContents.Replace("{localLink:", "{MyLink:");
            writer.Write(pageContents);
        }
    }
    

    The point here is that instead o calling the base.Render() i call the base.RenderChildren() in order to not run the Render method in the UmbracoDefault page, that replaces the localink stuff. Since there is not content in the actual .aspx page, i hope this doens have any bigger impact.

    Can anyone see a problem with this procedure? Would this break any existing umbraco functionality?

  • Laurence Gillian 600 posts 1219 karma points
    Oct 21, 2009 @ 11:08
    Laurence Gillian
    1

    Hello,

    I recently had a similar situation where I needed to override the default behavior for localLink rendering.

    I put together a solution using XSLT, I'm not sure how relevant this is to you, but I thought I makes sense for me to add it to this thread as it might help others.

    http://www.bysquirrels.com/2009/10/20/locallinks.aspx

    All the best, 

    Laurie

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Oct 21, 2009 @ 20:12
    Morten Bock
    0

    That definitely makes sense, and is less obtrusive than my solution, but was just not an option in my case.

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Oct 21, 2009 @ 20:40
    Niels Hartvig
    0

    Why would you want to override locallink?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Oct 21, 2009 @ 21:01
    Morten Bock
    0

    In our case we have an ecommerce website that relies on always having language and currency in the url. So a product has a url like:

    /da-dk/catalog/DKK/somecategory/someproduct/

    To be able to know the current currency while in a catalog, the content needs to be displayed with a currency in the url. So the same page exists in three different urls:

    /da-dk/content/DKK/somecontentpage/
    /da-dk/content/USD/somecontentpage/
    /da-dk/content/EUR/somecontentpage/

    So the link to the page depends on which currency we are currently using, and we don't want the same content in multiple places inside umbraco. But we still want to be able to use the standard linking stuff in the RTE, and also want to be able to insert any sort of macro in the RTE.

    So that is basically the reasoning behind it. I agree that currency might be better off somewhere else than in the URL, but that is not my call to make in this case :-)

  • Ben McKean 272 posts 549 karma points
    Sep 22, 2011 @ 23:18
    Ben McKean
    0

    @LaurenceG Do you still have that XSLT solution please?

    Your link is no longer working.

    Thanks

    Ben

  • Matthias 87 posts 173 karma points
    Sep 23, 2011 @ 08:24
    Matthias
    0

    Hi,

    i recently wrote a small XSLT Extension to solve a similar problem:
    http://blog.digital-bauhaus.de/blog/2011/september/replace-locallinks.aspx

    HTH
    Matthias

  • Ben McKean 272 posts 549 karma points
    Sep 23, 2011 @ 09:49
    Ben McKean
    0

    Thanks Matt.

    I can see how your solution would work.

    I ended up using doing something slightly different in the end. I waited until the content was redenered and then used JQuery to replace the text I wanted to. Not the prettiest piece of code but it works.

    I wanted to change a shared link to a company name in a URL.

    Not Umbraco specific really but here is the code if anybody is interested:

    StringBuilder replaceJS = new StringBuilder();
    replaceJS.AppendLine("$(\"#content\").html($(\"#content\").html().replace(/\\/shared-content\\//g,'/" + companyName.ToLower().Replace(" ", "-") + "/'));");
    Page.ClientScript.RegisterStartupScript(this.GetType(), "replaceSharedWithCompany", replaceJS.ToString(), true);

     

     

Please Sign in or register to post replies

Write your reply to:

Draft