Copied to clipboard

Flag this post as spam?

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


  • Mark Roffey 18 posts 32 karma points
    Jul 12, 2010 @ 13:22
    Mark Roffey
    0

    Intercept content and dynamically replace

    On the current project I'm working on, I need to replace a telephone number, depending on whether a cookie has been set. So the way I'm thinking at the minute, was that in the content, i'd put the number in as {TELEPHONE} and then intercept the content before it's rendered and replace as necesary.

    I've been trying to think of a way to do it in XSLT and using my own extensions, but it's a bit messy. Is there a way that I could do it from c# and extending Umbraco itself?

    Many thanks in advance for any help.

    Mark

     

  • Sascha Wolter 615 posts 1101 karma points
    Jul 12, 2010 @ 14:37
    Sascha Wolter
    0

    Hi Mark,

    you wouldn't necessarily have to write any custom extensions for it, you should be able to perform this with what you've already got in XSLT:

    <!-- retrieve the value from the cookie -->

    <xsl:variable name="cookieContent">

    <xsl:choose>

    <xsl:when test="string(umbraco.library:RequestCookies('yourCookieName')) != ''">

    <xsl:value-of select="string(umbraco.library:RequestCookies('yourCookieName'))" />

    </xsl:when>

    <xsl:otherwise>

    123456789

    </xsl:otherwise>

    </xsl:choose>

    </xsl:variable>

    <!-- replace instances of [TELEPHONE] with the value in the cookie -->

    <xsl:value-of select="Exslt.ExsltStrings:replace($currentPage/data[@alias='bodyText'], '[TELEPHONE]', '$cookieContent)" />

    I'd rather use square instead of curly brackets for that, just to be on the safe side.

    You can even go ahead and create a global XSLT file with a template that will take care of these replacements in a generic manner.

    Hope that was what you were looking

    Sascha

  • dan 29 posts 53 karma points
    Jul 13, 2010 @ 05:40
    dan
    0

    I think you can do something like this. Too

    <%@ Master Language="C#" MasterPageFile="/admin/masterpages/default.master" AutoEventWireup="true" %>
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
    
    string telephone = umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("telephone").Value;
        if (Session.Cookie.Isset) //Not sure about the code here.
        {
            telephone = "";
            lblTelephone.Text = telephone;
        }
        else
        {
            telephone = "";
        }
    </script>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    
        <asp:Label id="lblTelephone" runat="server"></asp:Label>    
    
    </asp:Content>
    
    Hope this helps you out.
    danielcruger.com
Please Sign in or register to post replies

Write your reply to:

Draft