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 https://github.com/twigphp/Twig/.

Basic usage

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>

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.

Tags

Peachpie Twig Web Mvc Razor

More information

Twig.AspNetCore
3.0.3
7/21/2021
github.com/jakubmisek/php-dotnet-projects

Share