当前位置: 首页>>代码示例>>C#>>正文


C# TemplateService.GetTemplate方法代码示例

本文整理汇总了C#中TemplateService.GetTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateService.GetTemplate方法的具体用法?C# TemplateService.GetTemplate怎么用?C# TemplateService.GetTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TemplateService的用法示例。


在下文中一共展示了TemplateService.GetTemplate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RazorEngineResultShouldContainTestText

        public void RazorEngineResultShouldContainTestText()
        {
            _templateRazor = string.Format("{0}{1}", "@{Layout=\"_layout\";}", _templateRazor);

            using (var service = new TemplateService())
            {
                service.GetTemplate(_layoutRazor, null, "_layout");
                service.GetTemplate(_templateRazor, _modelJson, "template");

                var result = service.Parse(_templateRazor, _modelJson, null, "page");

                Console.Write(result);
                Assert.IsTrue(result.Contains(MatchText));
            }
        }
开发者ID:rposbo,项目名称:razor-render,代码行数:15,代码来源:WhenReadingFromTheFileSystem.cs

示例2: ProcessSubContent

        private void ProcessSubContent(TemplateService service, Match match, dynamic model)
        {
            var subName = match.Groups[1].Value; // got an include/layout match?
            var subContent = GetContent(subName); // go get that template then
            ProcessContent(subContent, service, model); // recursively process it

            service.GetTemplate(subContent, model, subName); // then add it to the service
        }
开发者ID:rposbo,项目名称:create-flat-file-website-from-razor,代码行数:8,代码来源:RenderHtmlPage.cs

示例3: TemplateBase_CanRenderWithInclude_SimpleInclude

        public void TemplateBase_CanRenderWithInclude_SimpleInclude()
        {
            using (var service = new TemplateService())
            {
                const string child = "<div>Content from child</div>";
                const string template = "@Include(\"Child\")";
                const string expected = "<div>Content from child</div>";

                service.GetTemplate(child, "Child");
                string result = service.Parse(template);

                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:nvegamarrero,项目名称:RazorEngine,代码行数:14,代码来源:TemplateBaseTestFixture.cs

示例4: TemplateBase_CanRenderWithInclude_WithCurrentModel

        public void TemplateBase_CanRenderWithInclude_WithCurrentModel()
        {
            using (var service = new TemplateService())
            {
                const string child = "@model RazorEngine.Tests.TestTypes.Person\n<div>Content from child for @Model.Forename</div>";
                const string template = "@model RazorEngine.Tests.TestTypes.Person\[email protected](\"Child\")";
                const string expected = "<div>Content from child for Test</div>";
                var person = new Person { Forename = "Test" };

                service.GetTemplate(child, person, "Child");
                string result = service.Parse(template, person, null, null);

                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:rmeshksar,项目名称:RazorEngine,代码行数:15,代码来源:TemplateBaseTestFixture.cs

示例5: TemplateBase_CanRenderWithLayout_WithSimpleLayout

        public void TemplateBase_CanRenderWithLayout_WithSimpleLayout()
        {
            using (var service = new TemplateService())
            {
                const string parent = @"<div>@RenderSection(""TestSection"")</div>@RenderBody()";
                const string template = @"@{_Layout = ""Parent"";}@section TestSection {<span>Hello</span>}<h1>Hello World</h1>";
                const string expected = "<div><span>Hello</span></div><h1>Hello World</h1>";

                /* GetTemplate is the simplest method for compiling and caching a template without using a 
                 * resolver to locate the layout template at a later time in exection. */
                service.GetTemplate(parent, "Parent");
                string result = service.Parse(template);

                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:SaintLoong,项目名称:RazorEngineNET4.0,代码行数:16,代码来源:TemplateBaseTestFixture.cs

示例6: TemplateBase_CanRenderInclude_WithInlineTemplate

        public void TemplateBase_CanRenderInclude_WithInlineTemplate()
        {
            using (var service = new TemplateService())
            {
                const string child = "@model RazorEngine.Tests.TestTypes.InlineTemplateModel\[email protected](Model)";
                const string template = "@model RazorEngine.Tests.TestTypes.InlineTemplateModel\[email protected]{ Model.InlineTemplate = @<h1>@ViewBag.Name</h1>; }@Include(\"Child\", Model)";
                const string expected = "<h1>Matt</h1>";

                dynamic bag = new DynamicViewBag();
                bag.Name = "Matt";

                service.GetTemplate(child, null, "Child");
                string result = service.Parse(template, new InlineTemplateModel(), bag, null);
                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:rmeshksar,项目名称:RazorEngine,代码行数:16,代码来源:TemplateBaseTestFixture.cs

示例7: Issue133_ViewBagShouldPersistToIncludes

        public void Issue133_ViewBagShouldPersistToIncludes()
        {
            using (var service = new TemplateService())
            {
                const string child = "<h1>@ViewBag.Name</h1>";
                const string template = "@Include(\"Child\")";
                const string expected = "<h1>Matt</h1>";

                dynamic bag = new DynamicViewBag();
                bag.Name = "Matt";

                service.GetTemplate(child, null, "Child");
                string result = service.Parse(template, null, bag, null);

                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:rmeshksar,项目名称:RazorEngine,代码行数:17,代码来源:Release_3_0_TestFixture.cs

示例8: Main

        static void Main()
        {
            string dirsrc = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(Path.Combine(dirsrc, @"..\BBQ"));

            using (var service = new TemplateService())
            {
                service.AddNamespace("test_RazorHandy");

                service.GetTemplate(File.ReadAllText(@".\Views\Shared\_L.cshtml"), null, "~/Views/Shared/_L.cshtml");
                var result = service.Parse(File.ReadAllText(@".\Views\bbq\Index.cshtml"), new { }, null, "page");

                Directory.SetCurrentDirectory(dirsrc);

                File.WriteAllText(@".\BBQ_static\index.html", result);

            }
        }
开发者ID:alejandraa,项目名称:TaskMQ,代码行数:18,代码来源:create_BBQ_static_html.cs

示例9: TemplateBase_CanRenderWithLayout_WithComplexLayout

        public void TemplateBase_CanRenderWithLayout_WithComplexLayout()
        {
            using (var service = new TemplateService())
            {
                const string grandparent = @"<div>Message from Child Template (section): @RenderSection(""ChildMessage"")</div><div>Message from Parent Template (section): @RenderSection(""ParentMessage"")</div><div>Content from Parent Template (body): @RenderBody()</div>";
                const string parent = @"@{_Layout = ""GrandParent"";}@section ParentMessage {<span>Hello from Parent</span>}<p>Child content: @RenderBody()</p>";
                const string template = @"@{_Layout = ""Parent"";}@section ChildMessage {<span>Hello from Child</span>}<p>This is child content</p>";
                const string expected = "<div>Message from Child Template (section): <span>Hello from Child</span></div><div>Message from Parent Template (section): <span>Hello from Parent</span></div><div>Content from Parent Template (body): <p>Child content: <p>This is child content</p></p></div>";

                service.GetTemplate(parent, "Parent");
                service.GetTemplate(grandparent, "GrandParent");
                string result = service.Parse(template);

                Assert.That(result == expected, "Result does not match expected: " + result);
            }
        }
开发者ID:SaintLoong,项目名称:RazorEngineNET4.0,代码行数:16,代码来源:TemplateBaseTestFixture.cs


注:本文中的TemplateService.GetTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。