RazorLight icon indicating copy to clipboard operation
RazorLight copied to clipboard

Support relative paths on layout pages references

Open koculu opened this issue 5 years ago • 4 comments

Is your feature request related to a problem? Please describe. .cshtml files layout pages definitions are enforced to be rooted per site root. For file system configuration, the basic relative access should be supported.

Describe the solution you'd like

@{
    Layout = "../Layout.cshtml";
}

Above layout statement does not work.

Additional context A solution proposal: TemplateRenderer.RenderLayoutAsync calls _engineHandler.CompileTemplateAsync with a single parameter. A second parameter can be added to this call in order to give the relative information from the previousPage.Layout. Then CompileTemplateAsync function would be able to create relative path.

This proposal requires significant change on a public API. Hence I am not creating a PR.

koculu avatar Dec 22 '19 18:12 koculu

Currently, IEngineHandler.CompileTemplateAsync takes a key:

Task<ITemplatePage> CompileTemplateAsync(string key);

This key is a service locator - it does not GET anything, it's just a facade for the project system.

Let's start by adding a Xunit.SkippableFact to the test suite, here:

  • tests\RazorLight.Tests\Razor\FileSystemRazorProjectItemTest.cs

Then look here in FileSystemRazorProject.cs:

        public override Task<RazorLightProjectItem> GetItemAsync(string templateKey)
        {
            if (!templateKey.EndsWith(Extension))
            {
                templateKey = templateKey + Extension;
            }

            string absolutePath = NormalizeKey(templateKey);
            var item = new FileSystemRazorProjectItem(templateKey, new FileInfo(absolutePath));

            if(item.Exists)
            {
                item.ExpirationToken = fileProvider.Watch(templateKey);
            }

            return Task.FromResult((RazorLightProjectItem)item);
        }

jzabroski avatar Dec 23 '19 14:12 jzabroski

@koculu Are you still interested in this, or did you go in a different direction?

jzabroski avatar Mar 26 '20 01:03 jzabroski

@koculu Are you still interested in this, or did you go in a different direction?

I don't need this anymore, because I have switched to .Net core Razor.

koculu avatar Mar 26 '20 06:03 koculu

OK, I think this is an interesting feature, so I'll keep your request open.

jzabroski avatar Mar 26 '20 13:03 jzabroski