Skip to content

AddDynamicTemplates for embedded resources #534

Description

@sybaris

Is your feature request related to a problem? Please describe.
I want to use Layout but with embedded resources.
Currenlty, I use RazorLight without layouts. It works.

My current code is

        internal static string GenerateHtml<T>(string resourceName, T model)
        {
            var engine = new RazorLightEngineBuilder()
                .UseEmbeddedResourcesProject(typeof(RootTypeForEmbeddedResources).Assembly, typeof(RootTypeForEmbeddedResources).Namespace)
                //.AddDynamicTemplates(new Dictionary<string,string>()
                //{ {"_Layout.cshtml","<body>Test\r\n    @RenderBody()\r\n</body>" }}
                //)
                .SetOperatingAssembly(operatingAssembly)
                .UseMemoryCachingProvider()
                .EnableDebugMode()
                .Build();

            string html = engine.CompileRenderAsync<T>(resourceName, model).Result;
            return html;
        }

I test, if I use AddDynamicTemplates (commented code), it works too.
No I want to have a file "_Layout.cshtml" which is an embedded ressource.
Currently if I do nothing, I have the following Exception : "One or more errors occurred. (RazorLightProjectItem of type RazorLight.Razor.EmbeddedRazorProjectItem with key _Layout.cshtml could not be found by the RazorLightProject of type RazorLight.Razor.EmbeddedRazorProject and does not exist in dynamic templates. See the "KnownDynamicTemplateKeys" and "KnownProjectTemplateKeys" properties for known template keys.) ---> RazorLight.TemplateNotFoundException: RazorLightProjectItem of type RazorLight.Razor.EmbeddedRazorProjectItem with key _Layout.cshtml could not be found by the RazorLightProject of type RazorLight.Razor.EmbeddedRazorProject and does not exist in dynamic templates. See the "KnownDynamicTemplateKeys" and "KnownProjectTemplateKeys" properties for known template keys."

And KnownDynamicTemplateKeys is empty, and KnownProjectTemplateKeys does not contains my "_Layout.cshtml"

Describe the solution you'd like
Several solutions :
1°/ Create a "UseEmbeddedResourcesTemplate" like "UseEmbeddedResourcesProject"
2°/ Create a AddDynamicTemplatesFromResources
...

Additional context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions