Copied to clipboard

Flag this post as spam?

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


  • Markus Johansson 1913 posts 5760 karma points MVP c-trib
    Jan 20, 2012 @ 08:41
    Markus Johansson
    0

    Hook into the rendering

    Hi!

    I want to hook into the rendering of a content node. Let's say I have a string in the bodyText of a node. [mystring]. When this renders I would like to replace that string with something else.

    I've been looking att the BeforeUpdateDocumentCache-event but that would only allow me to change the document and I don't want my change to be permanent. Just only for this request. (or only in the node cache could work).

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 09:09
    Jeroen Breuer
    0

    Have a look at this blog to see if there's an event you can use: http://www.richardsoeteman.net/2009/02/22/UmbracoV4EventsDemo.aspx.

    If it's only for one request this wiki might also be interessting: http://our.umbraco.org/wiki/reference/code-snippets/add-fake-property-to-a-content-node. There you add a "temp/fake" property to a content node for only 1 request. You could also get an existing property and update that for 1 request in this way.

    Jeroen

  • Markus Johansson 1913 posts 5760 karma points MVP c-trib
    Jan 20, 2012 @ 09:16
    Markus Johansson
    0

    Hi!
    Yes i know about the events but I can't really find a hook that would do the job. I don't want to do the processing in a macro (like the razor example). I want it to either store the replace in the cache or perfom it at each request.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 20, 2012 @ 09:27
    Jeroen Breuer
    0

    Well that was just an example and I did everything in Razor so people would understand it better. In the situation where I needed this it was done in a static class which did everything I needed. You would still need to call it in Razor, but in a much cleaner way. Something like this:

    //getting the node normal
    dynamic currentNode = Modal;

    //getting the node with modified data for this 1 request
    dynamic currentNode = ProjectHelper.GetUpdatedNode(); 

    Maybe you can give your template a code behind and change the Modal in it's page load (didn't test if this is possible). If you do that make sure that the razor will be rendered on pre render so what you've done in the page load is available there.

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 20, 2012 @ 09:46
    Rodion Novoselov
    0

    Hi. I think that in scenario you have described you could just create a macro that will do all the job and that's allowed to be used inside RTE and insert it in your bodyText.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 20, 2012 @ 10:37
    Lee Kelleher
    0

    Hi Markus,

    Check out my Shortcodes package. (I'm replying from my mobile, and can't paste the link... Just search for it)

    Cheers, Lee.

  • Markus Johansson 1913 posts 5760 karma points MVP c-trib
    Jan 20, 2012 @ 10:38
    Markus Johansson
    0

    Hi!

    The thing is that this is suppose to be a part of a package where the content nodes will contain stuff in the bodyText (RTE) that should be replaced when the node is rendered as content on the site. But when it's used though the API the orginal values should be there. I guess a macro could do the work but I'm looking for a solution thats more "buildt in under the hood". Like if there was en event that fired when a page was rendered:

    If(loadedNode.Type = "yada")
    {
        // Replace stuff
    }

  • Markus Johansson 1913 posts 5760 karma points MVP c-trib
    Jan 20, 2012 @ 10:40
    Markus Johansson
    0

    @Lee - Awesome! Thats what I'm looking for! When dose the "replace" happen? On each request? Or when the cache is updated? Link: http://our.umbraco.org/projects/developer-tools/shortcodes

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 20, 2012 @ 10:44
    Lee Kelleher
    2

    The replacement happens in a Response.Filter, registered in a HttpModule. The source is up on my BitBucket, feel free to extract what you need.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 20, 2012 @ 10:57
    Rodion Novoselov
    0

    Nice stuff. It's a possible solution that I've already thought of as well. It's great that there's a ready-to-use module for it.

  • Markus Johansson 1913 posts 5760 karma points MVP c-trib
    Jan 20, 2012 @ 11:11
    Markus Johansson
    0

    @Lee - Great! This is what I was searching for. Many thanks!

Please Sign in or register to post replies

Write your reply to:

Draft