Copied to clipboard

Flag this post as spam?

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


  • philw 99 posts 434 karma points
    May 05, 2015 @ 10:10
    philw
    0

    Token replacement in content

    I need to do token replacement inside grids on the Umbraco Razor page in 7.2.*, replacing special tokens out of the text stream with values I pull from a separate billing system. So for example [[DAY_COST]] would be replaced in the HTML with "$35.00 plus GST" or whatever that happened to be.

    This talks about a similar problem but doesn't answer in a useful way for me:

      https://our.umbraco.org/forum/using/ui-questions/40886-Token-replacement-is-pages-How

    I don't see how a "macro" would help, as the user can't I think insert a macro into the Rich Text editor.. .unless I'm missing something. Really it needs to be as easy as typing [[ReplaceMeWithAValue]].

    I can work out how to "pipe" the output from the Razor View's file into some code which replaces the tokens with the values, but has anyone already done this, and what would be the neatest way to do it?

    I know how to do everything except plumb this into Umbraco neatly; the question is not about parsing, regex, or database caching etc. It's about where precisely in Umbraco is the cleanest place to put some additional processing into the text content pipeline.

     

     

  • Mehul Gajjar 48 posts 172 karma points
    May 05, 2015 @ 10:22
    Mehul Gajjar
    0

    Hi Philw,

    I have done such the things like below

    @Html.Partial("YOURVIEW").ToString().Replace("[[DAY_COST]]","$35.00 plus GST")
    

    Hope this is usefull

    Regards,

    Mehul Gajjar.

  • philw 99 posts 434 karma points
    May 05, 2015 @ 10:44
    philw
    0

    I think that is probably precisely what I need to know, although it may take me a few days to get time to test it. 

    In eg Bootstrap3.cshtml there's a @Html.Partial bit, which I looks like the place I need to be.

    So I think you're saying that the @Html.Partial returns plain text (or HTML), so I can pipe that into my parsing stuff.

    I'll report back. Thanks!

  • David Parr 48 posts 206 karma points
    May 05, 2015 @ 17:03
    David Parr
    100

    I've had to do something similar, may not be the best approach granted but it works fine and you can just do:

    var gridHtml = Model.Content.GetGridHtml("gridProperty").ToString();
    
    // Do replacements...
    gridHtml = gridHtml.Replace("[[DAY_COST]]", "whatever");
    
    @Html.Raw(gridHtml);
    

    Thanks, Dave

  • philw 99 posts 434 karma points
    May 09, 2015 @ 15:41
    philw
    0

    I just did that and it works as advertised - ta!
    I will try the other option in due course. 

Please Sign in or register to post replies

Write your reply to:

Draft