Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 961 Bytes

File metadata and controls

32 lines (22 loc) · 961 Bytes

MbSoftLab.TemplateEngine.Core.Razor

Optionales Erweiterungspaket für MbSoftLab.TemplateEngine.Core, das die RazorTemplateEngine<T> bereitstellt.

Installation

# .NET CLI
dotnet add package MbSoftLab.TemplateEngine.Core.Razor

# Oder Projekt-Referenz (Monorepo)
dotnet add <IhrProjekt>.csproj reference MbSoftLab.TemplateEngine.Core.Razor/MbSoftLab.TemplateEngine.Core.Razor.csproj

Verwendung

using MbSoftLab.TemplateEngine.Core;

public class Person : TemplateDataModel<Person>
{
    public string FirstName { get; set; }
}

var person = new Person { FirstName = "Anna" };

var engine = new RazorTemplateEngine<Person>();
engine.TemplateString = "<h1>@Model.FirstName</h1>";
string html = engine.CreateStringFromTemplate(person);

Hinweis: TemplateDataModel<T> ist nun eine einfache Klasse im Core (ohne Razor-Basis). Die Razor-Engine erhält intern Model als Datenmodell (template.Run(TemplateDataModel?.Model)).