Are nested templates supported?

Oct 17, 2011 at 3:26 AM
Edited Oct 17, 2011 at 3:27 AM

Hi,

I'm having trouble parsing a template which in turn parses a second template.  For example, given this template:

string innerTemplate = "Nested Template!";
string template = String.Format("Parent Template! @RazorEngine.Razor.Parse(\"{0}\") This text comes after the nested template.", innerTemplate);
string result = Razor.Parse(template);

 

I would expect the result to be:

Parent Template! Nested Template! This text comes after the nested template.

 

However, the actual result is:

Nested Template!Nested Template! This text comes after the nested template.

 

And if I include multiple nested templates:

 

string innerTemplate = "Nested Template!";
string innerTemplate2 = "Another Template!";
string template = String.Format("Parent Template! @RazorEngine.Razor.Parse(\"{0}\")... and another: @RazorEngine.Razor.Parse(\"{1}\") This text comes after the nested templates.", innerTemplate, innerTemplate2);
string result = Razor.Parse(template);

 

Then only the last template is included in the result:

Another Template!Another Template! This text comes after the nested templates.

 

It seems like each nested template clears the buffer of the previous templates and includes itself in the result twice.  Is there a way to execute nested templates like these?

Thanks,

Glen

Coordinator
Oct 31, 2011 at 1:48 PM

Hi,

Includes, Layouts and Sections are now supported in the upcoming v3 build. We are no longer pushing to Codeplex, instead we are pushing to Github (https://www.github.com/Antaris/RazorEngine)