The project provides Twig templates parsing and rendering for .NET.
The sources of original library are maintained at https://github.com/twigphp/Twig/.
Render Twig template in a razor page
Index.cshtml:
@{
ViewData["Title"] = "My Twig Page";
}
@Html.Twig("/path/to/templates", "index.html", new { name = "John Doe", });
path/to/templates/index.html:
<p>
Hello {{ Name }}!
</p>
The last argument specifies the template data. It can be any object
, PhpArray
, IDictionary
or null
. In case it is ommited or null
, the page's ViewData
are used implicitly.
The unmodified PHP code is compiled to .NET assembly using PeachPie PHP Compiler. Resulting library can be seamlessly referenced by other .NET projects (C#, VB.NET, F#), used for rendering Twig e.g. within ASP.NET Core pages. The library does not need PHP or a PHP server.
Id: | Twig.AspNetCore |
Version: | 3.0.3 |
Published: | 7/21/2021 |
Project URL: | github.com/jakubmisek/php-dotnet-projects |