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
    May 03, 2010 @ 17:39
    MrFlo
    0

    Full url on href src for newsletter template (2)

    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 (withhttp://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";

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

    }
    </script>

     

     This solution from Dan removes as well the friendly url system:

    <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 )" />

     

    Do you have an idea to have all absolute url everywhere without using a custom xslt on each page properties ?

    Thanks for your input,

    MrFLo

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    May 03, 2010 @ 20:37
    Sebastiaan Janssen
    0

    I just always use this:

      <xsl:variable name="urlPrefix">
        <xsl:text>http://</xsl:text>;
        <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" />
      </xsl:variable>

    And the links (including niceURL get built like this:

    <a>
     <xsl:attribute name="href">
      <xsl:value-of select="$urlPrefix"/>
      <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
     </xsl:attribute>
     <xsl:text>Some link text</xsl:text>
    </a>
  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    May 03, 2010 @ 22:02
    Morten Bock
    0

    You can write an httpmodule to parse your output for you. Then you should be able to hook into the output after umbraco has rendered the niceurl stuff.

  • MrFlo 159 posts 403 karma points
    May 04, 2010 @ 04:36
    MrFlo
    0

    It should work, but this is quiet a complex solution and it will reduce performance and it'll be applied on all the site.

    There is not a way to do it in tinyMCE?

    I am not the only one looking for this and still no solution for all that messages:

    http://our.umbraco.org/forum/using/ui-questions/4843-Editor-removing-external-link-when-its-the-same-as-the-domain

    http://our.umbraco.org/forum/using/ui-questions/7697-Cannon-enter-full-URL-in-text-in-tinyMCE

    If you know more thanks for your help!

  • MrFlo 159 posts 403 karma points
    May 04, 2010 @ 05:13
    MrFlo
    0

    This solution from Len seems to work in tinyMCE but you need to do this on each parent node...

     

    Hi,

    This is an issue that I have been checking and I think it is a bug in Umbraco.

    You can set the option <useDomainPrefixes>true</useDomainPrefixes> in the config file umbracosettings.config

    to true. Then you have to add the domain name/hostname to all pages on level 2, like this:

    Homepage > add hostname www.domain.com

    * Page1 > add hostname www.domain.com/page1 without the aspx

    * Page2 > add hostname www.domain.com/page2 without the aspx

    Now your niceurl will work and give you an absolute url because it will search for the domain names up to level 2. I have this working on our installation using umbraco 4 and we are trying to change the method that causes this behavior wich is niceurldo in the library.

    This is really a bug in Umbraco.

    thx, Len. 

     

    For my part the structure is /en/newsletter/...aspx 

    So I have define my hostname on www.domain.com/en and then on www.domain.com/en/newsletter

    Hope this help

     

  • 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