PHPackages                             kodi-app/kodi-twig-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. kodi-app/kodi-twig-provider

ActiveLibrary[Framework](/categories/framework)

kodi-app/kodi-twig-provider
===========================

KodiApp Twig provider

v0.9.3(8y ago)123Apache-2.0PHPPHP ^7.0

Since Sep 3Pushed 8y ago2 watchersCompare

[ Source](https://github.com/kodi-app/kodi-twig-provider)[ Packagist](https://packagist.org/packages/kodi-app/kodi-twig-provider)[ Docs](https://github.com/kodi-app/kodi-twig-provider)[ RSS](/packages/kodi-app-kodi-twig-provider/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

TwigProvider
============

[](#twigprovider)

ServiceProvider which provides Twig (with some extension) for KodiApp.

Installation
------------

[](#installation)

```
$ composer require kodi-app/kodi-twig-provider
```

About Twig
----------

[](#about-twig)

Check the [official documentation](https://github.com/nagyatka/pandabase)

Supported Twig version: v2.4.\*

We use the original Twig\_Environment to rendering thus you can use every functionality which it provides but we extended it with new `render()` function and ContentProviders for the easier usability.

Initialization of Twig (via TwigServiceProvider)
------------------------------------------------

[](#initialization-of-twig-via-twigserviceprovider)

Initialization of one connection:

```
$application->run([
    // ...
    KodiConf::SERVICES => [
        // List of Services
        [
            "class_name" => TwigServiceProvider::class,
            "parameters" => [
                // [Mandatory] Absolute path to directory which contains the *.twig files
                Twig::TWIG_PATH             => PATH_BASE."/src/KodiTest/View",

                // [Optional] Relative path to page template
                Twig::PAGE_TEMPLATE_PATH    => "/frame/frame.twig",

                // [Optional] List of ContentProviders
                Twig::CONTENT_PROVIDERS     => [
                    [
                        "class_name" => PageTitleProvider::class,
                        "parameters" => [
                            "name"  => "page_title",
                            "title" => "Hello world!"
                        ]
                    ],
                    // ...
                ]
            ]
        ]
        // ...
    ],
    // ...
]);
```

Usage of Twig
-------------

[](#usage-of-twig)

**Get Twig instance:**

```
/** @var Twig $twig You can get Twig via Application singleton instance */
$twig = Application::get("twig")->getTwigEnvironment;

/** @var Twig_Environment $twig If you want to use the original Twig_Environment */
$twig = $twig->getTwigEnvironment();
```

### About our Twig extension

[](#about-our-twig-extension)

In our extension we provide another concept of html content rendering (based in original twig) to reduce communication overhead between the server and the browser. We defined a so called page\_template which contains all the "static" parts of your page. For example a page\_template can contain page header, sidebar, footer, menu, etc.

**TODO: Finish the explanation of page\_template.**

#### Render function

[](#render-function)

```
/**
 * Renders the html content to string based on parameter. If the HTTP request is an AJAX request it will render only the template
 * in other cases it renders also the page_template and puts the template content to the appropriate position of the page_template.
 *
 * If you want to prevent the usage of page_template you have to set the $forceRawTemplate parameter to true.
 *
 *
 * @param string $templateName Relative path to *.twig template file
 * @param array $parameters Parameters for twig template file
 * @param bool $forceRawTemplate Prevents the rendering of page template of it is true.
 * @param null $pageTemplate Relative path to a page_template file if you dont want to use the default one.
 * @return string
 * @throws HttpInternalServerErrorException When the pageTemplate does not exist.
 */
public function render($templateName, array $parameters = [], bool $forceRawTemplate = false,$pageTemplate = null) {
    // ...
}
```

In the page\_template twig file you have to put following line. The twig will render your templates to this position.

```
    {% include app.content_template_name %}
```

#### ContentProviders

[](#contentproviders)

You are able to attach so called ContentProviders to `app` variable. You can define the list of used providers via the `Twig::CONTENT_PROVIDERS` configuration setting.

**Example of usage:**Configuration:

```
Twig::CONTENT_PROVIDERS => [
    [
        "class_name" => PageTitleProvider::class,
        "parameters" => [
            "name"  => "page_title",
            "title" => "Hello world!"
        ]
    ],
    // ...
]
```

In twig:

```
{{app.page_title}}
```

Notice that you have to use the `name` parameter (in configuration) to refer a ContentProvider.

**IMPORTANT:** In the extension, the `app` variable name is reserved for passing the ContentProviders in twig files!

If you want to create your own ContentProvider you have to implement the abstract ContentProvider class.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

4

Last Release

3145d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c4487ce24f1430bdd6cb97b9a532d2b59c270f1d27b6666c510d786fcdc0d737?d=identicon)[kodi-app](/maintainers/kodi-app)

---

Top Contributors

[![nagyatka](https://avatars.githubusercontent.com/u/3961400?v=4)](https://github.com/nagyatka "nagyatka (5 commits)")

---

Tags

phpframeworktwigkodiapp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kodi-app-kodi-twig-provider/health.svg)

```
[![Health](https://phpackages.com/badges/kodi-app-kodi-twig-provider/health.svg)](https://phpackages.com/packages/kodi-app-kodi-twig-provider)
```

###  Alternatives

[slim/twig-view

Slim Framework 4 view helper built on top of the Twig 3 templating component

3708.0M210](/packages/slim-twig-view)[contao-community-alliance/dc-general

Universal data container for Contao

1578.3k86](/packages/contao-community-alliance-dc-general)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
