Twig for ASP.NET Core

Fabien Potencier,Twig Team Free   Connect to feed
Provides Twig templates parsing and rendering for .NET.

The project provides Twig templates parsing and rendering for .NET.

The sources of original library are maintained at

Basic usage

Render Twig template in a razor page


    ViewData["Title"] = "My Twig Page";

@Html.Twig("/path/to/templates", "index.html", new { name = "John Doe", });


    Hello {{ Name }}!

Template data

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.

How it works

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.


Peachpie Twig Web Mvc Razor

More information