Copied to clipboard

Flag this post as spam?

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


  • Governor Technology 146 posts 551 karma points
    Feb 09, 2015 @ 15:23
    Governor Technology
    0

    How to inject html on the fly when rendering front end pages

    Hi there

    I have a common (configurable) html snippet that I need to insert across a large number of sites for (potentially) all front end pages of each site. I've created a package which will be installed for each site, but now need an efficient way to insert the html to be rendered on each front-end aspx page.

    I can see three options:

    1) Create a macro to manually insert the html and drop the macro in the relevant templates.

    2) Find a way to do a bulk update of the relevant templates files by changing their content and inserting the html (e.g. a post package install action).

    3) Find a way to hook into the dynamic rendering of front end aspx pages and inject the html on the fly together with the rest of the output without actually changing the content of the underlying template files.

    I want to pursue number 3 since this would be the best option in my case and also require the least amount of setup across the sites. My question is if this is possible at all?

    One way would be to use a http module/handler however since this would by default be applied for all http requests and requires filtering to only be applied on front end aspx pages, I'd rather find another solution. I don't have visibility over all the sites so this option is risky in the sense that it can potentially be applied on http responses which should not be altered.

    Another option might be to use the global.asax however in this case, I don't have access to this.

    I am therefore looking for a pure "Umbraco" way which I can be confident in dynamically injecting the html during the rendering process of front end aspx pages.

    A further complications is that the method for injecting the html needs to be as generic as possible to be applied across Umbraco versions 4 to 7.

    Unless I'm missing something obvious, so far I cannot see much on this out there. Any help on this would be appreciated!

    Best, Rig

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 10, 2015 @ 12:35
    Jeroen Breuer
    0

    Hello,

    There is an event in Umbraco where you can modify the model before it's send to the frontend view. More info here: http://issues.umbraco.org/issue/U4-5065

    Maybe that's something you can use?

    Jeroen

  • Governor Technology 146 posts 551 karma points
    Feb 10, 2015 @ 13:29
    Governor Technology
    0

    Hi Jeroen

    Thanks for your suggestion! I'm not sure however that this would work. The idea is not to change the model, but to change the html output generated by Umbraco based on a content node and it's template. This needs to be done by somehow hooking into the page rendering process when the aspx is generated dyanmically, and manually injecting some html, i.e. without actually changing the underlying template file. Or can changing the model somehow achieve this?

    Also, this solution seems to depend on the MVC components, however my package will have to work on earlier versions of Umbraco as well.

    It does seem that perhaps there is no way to achieve exactly what I'm after. The next best way would probably be to use a http module/handler and ensure to only apply it on front end pages.

    Regards, Rig

Please Sign in or register to post replies

Write your reply to:

Draft