RazorLight
RazorLight copied to clipboard
Support relative paths on layout pages references
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.
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);
}
@koculu Are you still interested in this, or did you go in a different direction?
@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.
OK, I think this is an interesting feature, so I'll keep your request open.