razor - Build a RazorEngine template by specifying a layout in the calling code rather than the template? -


using antaris razorengine, given 2 strings:

  • a razor template without layout specified

    <h1>my template</h1> 
  • and layout in should rendered

    <html>renderbody()</html> 

i able parse/compile strings , set layout in code performing parsing. like:

parsewithtemplate(templateasstring, layoutasstring, model, etc.); 

how might implement parsewithtemplate(string, string, ...) method?

background: i'm building static site generator , want way provide default layout don't have specify in every single 1 of many site pages. should possible override default if layout = "layoutname" provided in template.

if pre-compile layout template, should able set layout directly casting template templatebase. if later specify layout in template markup, override value in code require when template executes.

itemplateservice templateservice = ...;  // ensure layout template cached layoutcachename templateservice.gettemplate(layoutasstring, model, layoutcachename);  itemplate template = templateservice.gettemplate(templateasstring, model, templatecachename); var templatebase = template templatebase; if (templatebase != null) templatebase.layout = layoutcachename; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -