Copied to clipboard

Flag this post as spam?

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


  • Fergus Davidson 309 posts 588 karma points
    May 14, 2013 @ 13:22
    Fergus Davidson
    0

    Token replacement is pages - How??

    A site i am building at the moment requires the functionality to add tokens such as:

    [[firstname]]

    [[account_number]]

    ...to be added into content and replaced with values from a custon table. Some of these tokens will be single values, others will generate blocks of content [e.g. rate tables].

    The table is appended daily/hourly by SQL update from the client server and the value has to be the most recent.

    So the editor will write the content [page content, dictionary, macro, reusable content blocks] and include a token which needs to be replaced on page render.

    I am not a .net-er and need some help in identifying how this might be done.

    HTTPHandler?

    PageAdapter?

    is there a package i can't find.

    Ifsomeone has done this for a previous site and provide a hint or two, that would be great. If someone has a working example i can tweak, that would be fantastic.

     

    Thanks

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 15, 2013 @ 12:13
    Dave Woestenborghs
    0

    You can create a macro to display your RTE field.

    In this macro you can do the string replacement. 

    I used http://www.stringtemplate.org/ for token replacement in the past and it worked just fine. It has a .NET port

  • philw 99 posts 434 karma points
    Jun 03, 2013 @ 12:20
    philw
    0

    I have a simplar requirement I think. I want users to be able to easily insert key-worded fields from the page/ page hierachy. So for example [OpeningDay] would be replaced on render by a date. In other non-Umbraco systems I'd provide the value for OpeningDay as an application.config setting and let them edit it. Then, whevener it changed in that one place, all the rendered pages would naturally still show the correct value.

    Umbraco gives me an easy way for content users to pick that date, but using it is horrible. Specifially, I built a macro which takes parameter "Field Name", and walks up the tree looking for where that field has content, then they can insert that. It's a bit clunky to insert the macro, but it gets worse as on Medium Trust I can't render it, so instead of looking at [OpeningDay] in their "Rich Text", they see this horrid box thing which doesn't tell them what the content is, or the value of it. It's not really what I want.

     

    I'm unphased by .NET, and I can see how to pull arbitrary values from Umbraco in C#. The issue is... can anyone help me work out how to hook into the Umbraco page rendering so I can do a little old string replace on the content of each page?

  • philw 99 posts 434 karma points
    Jun 03, 2013 @ 13:04
    philw
    0

    I suppose I could write something that runs OnPreRender inside the template (master page). That would pull the "content" fields I want to display, and regex-replace any tokens I define with items from other Umbraco fields, specifically site-wide values from the site's roon node.

    (update..)

    That works, but if I process the content field and token-replace it using C#, say in OnPreRender, then any Umbraco macros that I do use in that content aren't expanded. I suppose as I'm using Umbraco Macros to add user controls anyway, I can add those controls in OnPreRender too.

     

    I can't help feel I'm missing something here as I think this ought to be a standard problem.

Please Sign in or register to post replies

Write your reply to:

Draft