Reputation: 3
I am using this https://antaris.github.io/RazorEngine/ as a guide.
This code:
using RazorEngine;
using RazorEngine.Templating; // For extension methods.
string template = "Hello @Model.Name, welcome to RazorEngine!";
var result =
Engine.Razor.RunCompile(template, "templateKey", null, new { Name = "World" });
Instead of using string template
... is it possible to reference it to a index.html
file to use as a template?
This is how the HTML file looks like..
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<header class="header" style="text-align: center;">
<p style="color: red;">Hello @Model.Name</p>
</header>
</body>
</html>
Upvotes: 0
Views: 53
Reputation: 218867
A string is a string, regardless of where it came from. You can use File.ReadAllText
to read a file as a string. For example:
string template = File.ReadAllText("index.html");
var result = Engine.Razor.RunCompile(template, "templateKey", null, new { Name = "World" });
Upvotes: 1