private string ActivateAndRenderTemplate(IRazorTemplateBase obj, DisplayContext displayContext, string templateVirtualPath, object model) {
            var buffer = new StringBuilder(1024);
            using (var writer = new StringWriter(buffer)) {
                using (var htmlWriter = new HtmlTextWriter(writer)) {

                    if (displayContext != null && displayContext.ViewContext.Controller != null) {
                        var shapeViewContext = new ViewContext(
                            displayContext.ViewContext.Controller.ControllerContext,
                            displayContext.ViewContext.View,
                            displayContext.ViewContext.ViewData,
                            displayContext.ViewContext.TempData,
                            htmlWriter
                            );

                        obj.WebPageContext = new WebPageContext(displayContext.ViewContext.HttpContext, obj as WebPageRenderingBase, model);
                        obj.ViewContext = shapeViewContext;

                        obj.ViewData = new ViewDataDictionary(displayContext.ViewDataContainer.ViewData) {Model = model};
                        obj.InitHelpers();
                    }
                    else {

                        obj.ViewData = new ViewDataDictionary(model);
                        obj.WebPageContext = new WebPageContext(_httpContextBase, obj as WebPageRenderingBase, model);
                    }

                    obj.VirtualPath = templateVirtualPath ?? "~/Themes/Orchard.Templates";
                    obj.Render(htmlWriter);
                }
            }

            return buffer.ToString();
        }
Beispiel #2
0
        private string ActivateAndRenderTemplate(IRazorTemplateBase obj, DisplayContext displayContext, string templateVirtualPath, object model)
        {
            var buffer = new StringBuilder(1024);

            using (var writer = new StringWriter(buffer)) {
                using (var htmlWriter = new HtmlTextWriter(writer)) {
                    if (displayContext != null && displayContext.ViewContext.Controller != null)
                    {
                        var shapeViewContext = new ViewContext(
                            displayContext.ViewContext.Controller.ControllerContext,
                            displayContext.ViewContext.View,
                            displayContext.ViewContext.ViewData,
                            displayContext.ViewContext.TempData,
                            htmlWriter
                            );

                        obj.WebPageContext = new WebPageContext(displayContext.ViewContext.HttpContext, obj as WebPageRenderingBase, model);
                        obj.ViewContext    = shapeViewContext;

                        obj.ViewData = new ViewDataDictionary(displayContext.ViewDataContainer.ViewData)
                        {
                            Model = model
                        };
                        obj.InitHelpers();
                    }
                    else
                    {
                        // Setup a fake view context in order to support razor syntax inside of HTML attributes,
                        // for instance: <a href="@WorkContext.CurrentSite.BaseUrl">Homepage</a>.
                        var viewData    = new ViewDataDictionary(model);
                        var httpContext = _wca.GetContext().HttpContext;
                        obj.ViewContext = new ViewContext(
                            new ControllerContext(
                                httpContext.Request.RequestContext,
                                new StubController()),
                            new StubView(),
                            viewData,
                            new TempDataDictionary(),
                            htmlWriter);

                        obj.ViewData       = viewData;
                        obj.WebPageContext = new WebPageContext(httpContext, obj as WebPageRenderingBase, model);
                        obj.WorkContext    = _wca.GetContext();
                    }

                    obj.VirtualPath = templateVirtualPath ?? "~/Themes/Orchard.Templates";
                    obj.Render(htmlWriter);
                }
            }

            return(buffer.ToString());
        }
        private string ActivateAndRenderTemplate(IRazorTemplateBase obj, DisplayContext displayContext, string templateVirtualPath, object model) {
            var buffer = new StringBuilder(1024);
            using (var writer = new StringWriter(buffer)) {
                using (var htmlWriter = new HtmlTextWriter(writer)) {

                    if (displayContext != null && displayContext.ViewContext.Controller != null) {
                        var shapeViewContext = new ViewContext(
                            displayContext.ViewContext.Controller.ControllerContext,
                            displayContext.ViewContext.View,
                            displayContext.ViewContext.ViewData,
                            displayContext.ViewContext.TempData,
                            htmlWriter
                            );

                        obj.WebPageContext = new WebPageContext(displayContext.ViewContext.HttpContext, obj as WebPageRenderingBase, model);
                        obj.ViewContext = shapeViewContext;

                        obj.ViewData = new ViewDataDictionary(displayContext.ViewDataContainer.ViewData) { Model = model };
                        obj.InitHelpers();
                    }
                    else {

                        // Setup a fake view context in order to support razor syntax inside of HTML attributes,
                        // for instance: <a href="@WorkContext.CurrentSite.BaseUrl">Homepage</a>.
                        var viewData = new ViewDataDictionary(model);
                        var httpContext = _wca.GetContext().HttpContext;
                        obj.ViewContext = new ViewContext(
                            new ControllerContext(
                                httpContext.Request.RequestContext,
                                new StubController()),
                                new StubView(),
                                viewData,
                                new TempDataDictionary(),
                                htmlWriter);

                        obj.ViewData = viewData;
                        obj.WebPageContext = new WebPageContext(httpContext, obj as WebPageRenderingBase, model);
                        obj.WorkContext = _wca.GetContext();
                    }

                    obj.VirtualPath = templateVirtualPath ?? "~/Themes/Orchard.Templates";
                    obj.Render(htmlWriter);
                }
            }

            return buffer.ToString();
        }
Beispiel #4
0
        private string ActivateAndRenderTemplate(IRazorTemplateBase obj, DisplayContext displayContext, string templateVirtualPath, object model)
        {
            var buffer = new StringBuilder(1024);

            using (var writer = new StringWriter(buffer)) {
                using (var htmlWriter = new HtmlTextWriter(writer)) {
                    if (displayContext != null && displayContext.ViewContext.Controller != null)
                    {
                        var shapeViewContext = new ViewContext(
                            displayContext.ViewContext.Controller.ControllerContext,
                            displayContext.ViewContext.View,
                            displayContext.ViewContext.ViewData,
                            displayContext.ViewContext.TempData,
                            htmlWriter
                            );

                        obj.WebPageContext = new WebPageContext(displayContext.ViewContext.HttpContext, obj as WebPageRenderingBase, model);
                        obj.ViewContext    = shapeViewContext;

                        obj.ViewData = new ViewDataDictionary(displayContext.ViewDataContainer.ViewData)
                        {
                            Model = model
                        };
                        obj.InitHelpers();
                    }
                    else
                    {
                        obj.ViewData       = new ViewDataDictionary(model);
                        obj.WebPageContext = new WebPageContext(_httpContextBase, obj as WebPageRenderingBase, model);
                    }

                    obj.VirtualPath = templateVirtualPath ?? "~/Themes/Orchard.Templates";
                    obj.Render(htmlWriter);
                }
            }

            return(buffer.ToString());
        }