Copied to clipboard

Flag this post as spam?

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


  • MrFlo 159 posts 403 karma points
    Apr 27, 2010 @ 01:47
    MrFlo
    0

    Get absolute URL on href src for newsletter template

    Hello

    I have made a newsletter template. I use the generated html from umbraco and then I copy/pasted it to a newsletter software.

    I am looking for a way to transform on the fly all relatives urls (in freetext editor) to an absolute one (with http://www...)

     

    It's possible to override the render and execute some RegEx or replace like this but it removes the nice url transformation.

    <script  runat="server">

           protected override void Render(HtmlTextWriter writer)

            {

               System.Text.StringBuilder htmlString = new StringBuilder(); // this will hold the string

               System.IO.StringWriter stringWriter = new System.IO.StringWriter(htmlString);

               System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

               base.Render(htmlWriter);

               htmlWriter.Flush();

               writer.Write(ReplaceUrl(stringWriter.ToString()));

            }

     

            private string ReplaceUrl(string p)

            {

                string url = "http://www.gondwana-dmcs.net";

                p = p.Replace("href=\"/", "href=\""+url+"/");

      return p;

    }

    </script>

     

     

    Do you have an idea to have all absolute url everywhere? Or a system to make the exportation to a newsletter tool easier ?

     

    Thanks a lot!

  • MrFlo 159 posts 403 karma points
    Apr 27, 2010 @ 02:05
  • MrFlo 159 posts 403 karma points
    Apr 27, 2010 @ 15:43
    MrFlo
    0

    The previous post wasn't a good solution. Anybody has an idea to accomplish this ? Thanks

  • dandrayne 1138 posts 2262 karma points
    Apr 27, 2010 @ 16:16
    dandrayne
    0

    You may be able to try a little replace as you output the values? Hacky but should work

    <xsl:variable name="absoluteThing"><xsl:text>href="/</xsl:text></xsl:variable>
    <xsl:variable name="fullThing"><xsl:text>href="http://www.yoursite.com/</xsl:text></xsl:variable>
    <xsl:value-of select="umbraco.library:Replace($currentPage/data[@alias='pageContent'],$absoluteThing, $fullThing )" />

    Dan

  • bob baty-barr 1180 posts 1294 karma points MVP
    Apr 27, 2010 @ 16:40
    bob baty-barr
    0

    this simple line of xslt gives you the full url of the current page....

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

    so, i imagine you could use that as a start...

    of course, there is also my favorite... jquery :)

    http://projects.allmarkedup.com/jquery_url_parser/

     

  • MrFlo 159 posts 403 karma points
    Apr 27, 2010 @ 18:09
    MrFlo
    0

    Thanks for your answers, will try the dandrayne solutions in a macro.

    Bob, the problem is that the urls are included in the text I received from the tidy editor so I need something like a find/replace or a system to change the wysiwyg comportment to always use full url...

    Any other ideas?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Apr 27, 2010 @ 20:27
    bob baty-barr
    0

    what about setting a <base/> attribute in your template?

    <BASE HREF="http://www.yourdomain.com" TARGET="_top">

    not sure that helps for the mail being forwarded... but would do the trick.

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 12x admin c-trib
    Apr 27, 2010 @ 20:43
    Jan Skovgaard
    0

    I have also been using the <base/> element for this. And it seemed to be working fine even though I'm not sure that it's 100% bulletproof though.

    /Jan

  • bob baty-barr 1180 posts 1294 karma points MVP
    Apr 28, 2010 @ 04:58
    bob baty-barr
    0

    i think the base tag fails when the message is forwarded... some clients strip it... i think...

  • MrFlo 159 posts 403 karma points
    Apr 28, 2010 @ 13:21
    MrFlo
    0

    Yes, actually the best thing will be a check and replace after  the render of the page on each HREF and SRC to be sure. 

    And not on all website, only in some template like a newsletter one.

    So if you have a lot of different properties/field you don't have to add the dandrayne macro on each field....

     

     

  • Fergus Davidson 309 posts 588 karma points
    Apr 28, 2010 @ 15:46
    Fergus Davidson
    0

    can you not just use something like:

    http://<xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" /><xsl:value-of select="umbraco.library:NiceUrl(@id)" />
  • dandrayne 1138 posts 2262 karma points
    Apr 28, 2010 @ 16:08
    dandrayne
    0

    I wouldn't be certain that base href will survive in online mail clients (gmail etc), as they strip out any html that could interfere with the surrounding page.

  • MrFlo 159 posts 403 karma points
    Apr 30, 2010 @ 18:03
    MrFlo
    0

    I have test your solution dandrayne, it works only for url that you type your self wihtout selecting a page.

    If you select an existing page your have an url like this: href="http://www.yoururl.com/{localLink:1356}

    So It finally wasn't the solution. The best solution would be something that replace all urls after the Render without removing the replacement of localLink...

    Any ideas ?

     

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies