asp.net-coreblazorrazorenginerazorlight

Razor Page HTML Rendering via RazorLight.NetCore3 Template Key


I have recently integrated this RazorLight package for Razor page rendering. While using I came to notice that there is a Template key that has to be defined. What actually this template key is and what it does?

 var result = await engine.CompileRenderStringAsync("Template", content, model);

Here, the first argument takes a Template key. If i use a different template, then should i use the same key or different?


Solution

  • What actually this template key is and what it does?

    If i use a different template, then should i use the same key or different?

    Each template should have a templateKey that is associated with it while we create a template from string, so that we can re-run the cached template with this key. And the templateKey should be unique.

    string result = await engine.CompileRenderStringAsync("templateKey_here", template, model);
    
    //...
    
    var cacheResult = engine.Handler.Cache.RetrieveTemplate("templateKey_here");
    

    For more information about concept and use of RazorLight, please check following link:

    https://github.com/toddams/RazorLight