我用下面的片段来使剃刀模板我的解决方案(外ASP.NET MVC3的)。是否有可能的轻松的实施布局?
I'm using the following snippet to enable Razor templating in my solution (outside of ASP.NET MVC3). Is it possible to easily implement layouts?
我在这一点上(模板编译成 compiledTemplateAssembly
):
I'm at this point (templates are compiled into compiledTemplateAssembly
):
var template = (RazorTemplateBase<TModel>) compiledTemplateAssembly.
CreateInstance("RazorSpace." + entry.TemplateName + "Template");
template.Model = model;
template.Execute();
var output = template.Buffer.ToString();
template.Buffer.Clear();
return output;
我可以想像有我的 RazorTemplateBase
类布局
属性。但是之后?据我所知, Html.Partial
是我可以实现解析模板的辅助函数。但我怎么分析这些方法调用 renderBody()
或 renderSection()
来接受其他刀片的看法?
I can imagine having a Layout
property on my RazorTemplateBase
class. But then? I understand that Html.Partial
is a helper function which I can just implement to parse a template. But how do I parse those method calls renderBody()
or renderSection()
to accept other Razor views?
我目前正在对一些非常相似。它是一种基于南希前端模板框架。我延长了南希剃刀实施菲尔哈克。我设法得到谐音,模板化助手和布局工作。
I'm currently working on something very similar. It is a front end templating framework based on Nancy. I extended the Nancy's Razor implementation by Phil Haack. I have managed to get Partials, Templated Helpers and Layouts working.
要呈现的布局我有一个布局属性和布局里面我有一个内容占位符{{内容}}。所以,当我渲染视图如果布局属性设置我呈现布局,然后替换内容占位符。
To render the layout I have a Layout property and inside the layout I have a content placeholder "{{content}}". So when I render the view if the Layout property is set I render the layout and then replace the content placeholder.
该项目被称为阿皮亚。看一看在样品景观。
The project is called Appia. Have a look at the sample views.
下面是我的基本视点实施基本视点实施在这里是视图引擎code 。它借用了很多从MVC剃刀实施,也有一些南希具体的东西,但它不应该太很难搞清楚发生了什么。
Here is my baseView implementationbaseView implementation and here is the view engine code. It borrows a lot from the MVC Razor implementation and also has some Nancy specific stuff but it shouldn't be too hard to figure out what's happening.