al3xnull
al3xnull

Reputation: 866

Intercept Rendered HTML / Runtime HTML for Pages in Sitecore

Currently, I'm looking to create a page hierarchy outside of the main 'content' sections as to keep it separate from other sections and to keep it with all other cross site data. I'm able to assign layouts, sublayouts, and get content back in the way that I would like to.

However, I need the content as XHTML (very simple XHTML currently) to push it through iTextSharp & Html Tidy or equivalent. Is there a pipeline or event that I would be able to hook so that I could either get most of the page or all of the page response?

I noticed the Sitecore.Layouts namespace includes Converter, DesignTimeHtml, and RuntimeHtml, the latter of which references the convertToRuntimeHtml pipeline, which seems to pass around an HtmlDocument. These seem to be pipelines relating to the WYSIWYG editor though.

If nothing as such exists, would finding all the controls on the page and then rendering them out come close to what Sitecore would render?

Upvotes: 0

Views: 2470

Answers (3)

Sean Kearney
Sean Kearney

Reputation: 4008

I'm not sure you would have the low level access you need within a Sitecore pipeline to access the rendered HTML output of a System.Web.UI.Control, which is ultimately what a sublayout boils down to. And I am almost positive there is no Sitecore pipeline that would have the entire rendered page.

From what I've seen while quickly looking in Reflector, the RenderLayout Sitecore pipelines will allow you modify the process as a Sublayout Item is linked up with its user control counterpart. The RenderingReference is then added to Sitecore.Context.PageContext. The Sitecore.Web.UI.WebControls.Placeholder is then in charge of getting all the RenderingReferences and calling the System.Web.UI.Control.RenderControl()` method.

Being that Sitecore is calling System.Web.UI.Control.RenderControl() on all your sublayouts and basically throwing the output to the browser, without pushing the rendered HTML through a pipeline, you may want to look at a non-Sitecore solution.

You could override all of the Render(HtmlTextWriter writer) methods on your user controls, but that is a lot of duplicate coding (unless you have a single base control?). Your best bet may be to use an ASP.NET HttpModule to do the formatting after the entire page has been generated and about to go to the client. Here is one example - http://madskristensen.net/post/A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx

Upvotes: 2

Ruud van Falier
Ruud van Falier

Reputation: 8877

I have done this recently and found that the <convertToRuntimeHtml> pipeline did not work for me. Instead i have added my processor to the <renderField> pipeline which works for at least the sc:fld function (and thus also for the <sc:text> tag).

This is the code for my processor:

public class ContentVariablesProcessor
{
    public void Process(Sitecore.Pipelines.RenderField.RenderFieldArgs args)
    {
        if (args != null)
        {
            // Manipulate output
            args.Result.FirstPart = "my output";
        }
    }
}

Upvotes: 1

Mark Ursino
Mark Ursino

Reputation: 31435

You could perhaps add a custom processor in the renderLayout pipeline. I recommend you really just create a processor for various pipelines and see what you can access for them. An easy way to do this would be to de-compile Sitecore.kernel.dll and look at the pipeline args objects for each pipeline in kernel\Sitecore.Pipelines.{the pipeline name here}\{the pipeline name here}Args.cs. Once you investigate the args objects for each pipeline, that can help you know which args object provides access to what you need in C#. From there you can test an implementation within that pipeline.

Upvotes: 3

Related Questions