Kephas.Templating.Razor
11.0.0-dev.3
Prefix Reserved
See the version list below for details.
dotnet add package Kephas.Templating.Razor --version 11.0.0-dev.3
NuGet\Install-Package Kephas.Templating.Razor -Version 11.0.0-dev.3
<PackageReference Include="Kephas.Templating.Razor" Version="11.0.0-dev.3" />
<PackageVersion Include="Kephas.Templating.Razor" Version="11.0.0-dev.3" />
<PackageReference Include="Kephas.Templating.Razor" />
paket add Kephas.Templating.Razor --version 11.0.0-dev.3
#r "nuget: Kephas.Templating.Razor, 11.0.0-dev.3"
#:package Kephas.Templating.Razor@11.0.0-dev.3
#addin nuget:?package=Kephas.Templating.Razor&version=11.0.0-dev.3&prerelease
#tool nuget:?package=Kephas.Templating.Razor&version=11.0.0-dev.3&prerelease
Templating.Razor
Introduction
This package provides the implementation of templating using Razor syntax and *.cshtml files.
The cshtml template kind is handled by the RazorTemplatingEngine.
Usage
This is the content of the template.cshtml file.
@model TemplateModel
<div>Hi @Process(Model.Name)!</div>
@functions {
private string Process(string str)
{
return $"@{str}@";
}
}
record TemplateModel(string Name);
// normally you would get the processor injected into the service constructor.
var processor = injector.Resolve<ITemplateProcessor>();
var result = processor.Process(new FileTemplate("C:\\Path\\To\\template.cshtml"), new TemplateModel("Johnny"));
Assert.Equals("<div>Hi @Johnny@!</div>\r\n", result);
// this is a simpler alternative for Razor file templates.
var result = processor.ProcessWithFile("C:\\Path\\To\\template.cshtml", new TemplateModel("Johnny"));
Assert.Equals("<div>Hi @Johnny@!</div>\r\n", result);
// it is also possible to use string templates.
var template = @"
@model TemplateModel
<div>Hi @Process(Model.Name)!</div>
@functions {
private string Process(string str)
{
return $""@{str}@"";
}
}
";
var result = processor.ProcessWithRazor(template, new TemplateModel("Johnny"));
Assert.Equals("<div>Hi @Johnny@!</div>\r\n", result);
Additional services
All the enumerated services provide a default implementation which can be overridden if required. However, this should be rarely needed, instead configure the template generation
IMetadataReferenceManager
This internal service is used to provide MetadataReferences out of a list of assemblies.
IRazorProjectFileSystemProvider
Based on the template and the processing context, this service should provide a RazorProjectFileSystem used by the renderer.
The default implementation SimpleRazorProjectFileSystemProvider uses a simple strategy which handles a single template file without any additional template references.
IRazorProjectEngineFactory
Creates the Razor project engine for the provided file system and with the given context.
IRazorPageGenerator
Generates the C# code based on the provided project engine and item.
IRazorPageCompiler
Compiles the template with model type T and returns a ICompiledRazorPage<T> wrapped into an operation result.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Kephas.Templating (>= 11.0.0-dev.3)
- Microsoft.AspNetCore.Mvc.Razor.Extensions (>= 6.0.1)
- Microsoft.AspNetCore.Razor.Language (>= 6.0.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.1.0 | 720 | 4/13/2022 |
| 11.1.0-dev.4 | 285 | 4/6/2022 |
| 11.1.0-dev.3 | 264 | 3/30/2022 |
| 11.1.0-dev.2 | 275 | 3/23/2022 |
| 11.1.0-dev.1 | 268 | 3/23/2022 |
| 11.0.0 | 631 | 3/11/2022 |
| 11.0.0-dev.7 | 285 | 3/7/2022 |
| 11.0.0-dev.6 | 290 | 2/28/2022 |
| 11.0.0-dev.5 | 288 | 2/26/2022 |
| 11.0.0-dev.4 | 307 | 2/24/2022 |
| 11.0.0-dev.3 | 319 | 2/23/2022 |
| 11.0.0-dev.2 | 283 | 2/18/2022 |
Please check https://github.com/kephas-software/kephas/releases for the change log.
Also check the documentation and the samples from https://github.com/kephas-software/kephas/wiki and https://github.com/kephas-software/kephas/tree/master/Samples.