Copied to clipboard

Flag this post as spam?

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


  • Danny Douglass 28 posts 43 karma points
    Sep 09, 2009 @ 21:51
    Danny Douglass
    0

    Content Interception

    Greetings,

    Umbraco 4.0.2.1

    I have a requirement to intercept published content and manipulate a few different parts prior to their rendering on the front-end website.  I've been trying to work with the BeforeContentControlLoad event.  I've included the code below.  This file is sitting in App_Code/Events/InterceptContent.cs.  I can't seem to get the event to fire.  Any ideas where I'm going wrong?

    Thanks!

     

     

    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.web;
    using umbraco.controls;
    namespace Umbraco.Extensions.app_code.Events
    {
        public class ParseContent : ApplicationBase
        {
            public ParseContent() {
                ContentControl.BeforeContentControlLoad +=
                    new ContentControl.BeforeContentControlLoadEventHandler(Content_BeforeLoad);
            }
            public void Content_BeforeLoad(
          ContentControl sender, 
          umbraco.controls.ContentControlLoadEventArgs e) {
                object content = null;
                Log.Add(LogTypes.Custom, 12714, "Custom BeforeContentControlLoad Event Raised");
                }
            }
        }
    }

     

  • Tim 225 posts 690 karma points
    Sep 09, 2009 @ 22:13
    Tim
    0

    I suspect that you will need to compile your extesion into a DLL as I think that Umbraco uses reflection to register events such as this at application start up.

    So it's likely your event is never getting registered.

    Tim

  • Danny Douglass 28 posts 43 karma points
    Sep 10, 2009 @ 13:45
    Danny Douglass
    0

    Thanks for the response Tim.  I worded my original post poorly.  I currently have the event handler in a supporting Umbraco.Extensions project that is bundled into a .dll and copied into the Umbraco/bin folder.  The event should be able to be loaded through reflection without an issue.

    Perhaps I do not understand when this event is fired.  Is it on any document load on the front-end website?  That is the event I'm looking for, but I'm not sure what a "ContentControl" is referring to exactly.  

    Any insight is greatly appreciated!

    Cheers,
    --
    Danny

  • Tim 225 posts 690 karma points
    Sep 10, 2009 @ 14:21
    Tim
    0

    Ahh right I see now.

    The event you are firing is for the backend of Umbraco, when the content control is loaded into the editor.

    For the front end I'm not aware of an event that would fit the bill.

    If all you are trying to do is fiddle with some content that would normally be included in the template via a <umbraco:Item> tag you could:

    Write a user control which grabbed the item via the Umbraco API and did the content change then rendered it to the page.

    Write an XSLT macro which would do similar.

    You could have some c# code on the template which on Page_Load looked for the <umbraco:Item> in question by ID and did some fiddling.

    As I say it depends very much on what you are after.

    Tim

     

  • Danny Douglass 28 posts 43 karma points
    Sep 10, 2009 @ 15:12
    Danny Douglass
    0

    Thanks for the post - that solution works!

  • Tim 225 posts 690 karma points
    Sep 10, 2009 @ 15:22
    Tim
    0

    Which one?

    And don't forget to mark the post as solved!

    Glad I could help.

    Tim

Please Sign in or register to post replies

Write your reply to:

Draft