diff --git a/Nustache.Core/Template.cs b/Nustache.Core/Template.cs index acdda4d..5791a7c 100644 --- a/Nustache.Core/Template.cs +++ b/Nustache.Core/Template.cs @@ -6,7 +6,12 @@ namespace Nustache.Core public class Template : Section { public Template() - : base("#template") // I'm not happy about this fake name. + : this("#template") // I'm not happy about this fake name. + { + } + + public Template(string name) + : base(name) { } diff --git a/Nustache.Core/TemplateDefinition.cs b/Nustache.Core/TemplateDefinition.cs index 60a619f..78be378 100644 --- a/Nustache.Core/TemplateDefinition.cs +++ b/Nustache.Core/TemplateDefinition.cs @@ -1,6 +1,8 @@ namespace Nustache.Core { - public class TemplateDefinition : Section + public class TemplateDefinition : Template // This derives from Template so that it can + // be returned from a TemplateLocator. + // Should we make it implement an interface instead? { public TemplateDefinition(string name) : base(name) diff --git a/Nustache.Mvc3.Example/Views/Home/Index.mustache b/Nustache.Mvc3.Example/Views/Home/Index.mustache index 206052d..10747ec 100644 --- a/Nustache.Mvc3.Example/Views/Home/Index.mustache +++ b/Nustache.Mvc3.Example/Views/Home/Index.mustache @@ -2,4 +2,8 @@

{{ Message }} -

\ No newline at end of file +

+ +{{This is a nested section.

+{{/Section}} \ No newline at end of file diff --git a/Nustache.Mvc3.Example/Views/Shared/_Layout.mustache b/Nustache.Mvc3.Example/Views/Shared/_Layout.mustache index c24544b..8b18173 100644 --- a/Nustache.Mvc3.Example/Views/Shared/_Layout.mustache +++ b/Nustache.Mvc3.Example/Views/Shared/_Layout.mustache @@ -10,5 +10,8 @@ {{>Body}} + +

Now including section defined in the view:

+ {{>Section}} diff --git a/Nustache.Mvc3/NustacheView.cs b/Nustache.Mvc3/NustacheView.cs index 37a938c..cf0006b 100644 --- a/Nustache.Mvc3/NustacheView.cs +++ b/Nustache.Mvc3/NustacheView.cs @@ -19,6 +19,8 @@ public NustacheView(ControllerContext controllerContext, string viewPath, string public void Render(ViewContext viewContext, TextWriter writer) { + var viewTemplate = GetTemplate(_viewPath); + if (!string.IsNullOrEmpty(_masterPath)) { var masterTemplate = GetTemplate(_masterPath); @@ -28,18 +30,23 @@ public void Render(ViewContext viewContext, TextWriter writer) { if (name == "Body") { - return GetTemplate(_viewPath); + return viewTemplate; } + else + { + var section = viewTemplate.GetTemplateDefinition(name); - // TODO: Figure out how to render sections. - // Wouldn't those be defined in the view like in Razor? + if (section != null) + { + return section; + } + } return null; }); } else { - var viewTemplate = GetTemplate(_viewPath); viewTemplate.Render(viewContext.ViewData.Model ?? viewContext.ViewData, writer, null); } }