开发者

Modifying Page controls from Xslt helper function class in Sitecore

Within an xslt render I call the following

<xsl:value-of select="di:inject()"/>

The corresponding class retrieves the current page object and attempts to modify 开发者_JS百科the page header

public class XslHelper : Sitecore.Xml.Xsl.XslHelper
{
    public void inject()
    {
        Page page = HttpContext.Current.Handler as Page;

        // page.GetType().FullName tells me that I have successfully got the reference

        page.Header.Controls.Add(new HtmlLink { Href = "/style.css" });
    }
}

However the header does not get updated? Why is this and is there another way to achieve the same result?

EDIT: We ended up extending the XslRender template and storing dependencies there instead, which can then be picked up and added to the session by overriding the InsertRenderings class in the renderLayout pipeline. The session object can then be accessed on Page_Load in the layout, which can access the header of the page.


I suspect that it is too late to add anything to the head part when XSL rendering is being rendered. And also, the only option could be to switch to sublayout and do this in Page_Load or something.

Can't prove my answer - it's just a gut feeling. That's why +1 to the question and added to favorites ;-)


You'd probably be better off just having all your classes in a single static CSS file. The additional overhead of HTTP requests and CPU load makes it hard to justify the benefits gained from dynamically loading CSS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜