TopazView is a lightweight view engine that utilizes the Topaz JavaScript Engine.
$ dotnet add package TopazViewTopazView is a lightweight view engine that utilizes the Topaz JavaScript Engine. It serves as an alternative to the Razor View Engine, offering several key features and benefits.
The following sample shows the most basic setup of the TopazView.
using Tenray.TopazView;
var path = "web/views";
var viewEngine = new ViewEngineFactory()
.SetContentProvider(new FileSystemContentProvider(path))
.CreateViewEngine();
var contentWatcher = new FileSystemContentWatcher();
contentWatcher.StartWatcher(path, viewEngine);
The following is a sample of view rendering.
using Tenray.TopazView;
var context = viewEngine.CreateViewRenderContext();
context.Model = new { Title = "My Awesome TopazView Template" }.ToJsObject();
var html = await ViewEngine
// provide an existing text file's relative path with any extension.
.GetOrCreateView("/home/index.view")
.GetCompiledView()
.RenderViewToString(context);
The following is a sample view template file (index.view).
@Layout="../layouts/layout.view"
<div>@model.Title</div>
@{
for(const i of [1,2,3]) {
page.raw(i + ' <br>')
}
}
@if(@model.Title) {
<div>model has a title.</div>
}
else {
<div>model has no title.</div>
}
Experience the live editor of TopazView to witness TopazView in action. TopazView WebView 2 Sample
To further enhance TopazView, the following tasks are on the agenda:
Feel free to contribute to the project by tackling any of these tasks or suggesting additional improvements. Your involvement is greatly appreciated!