PHPackages                             devknown/twig-import-function - 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. [Templating &amp; Views](/categories/templating)
4. /
5. devknown/twig-import-function

ActiveLibrary[Templating &amp; Views](/categories/templating)

devknown/twig-import-function
=============================

Call (almost) any PHP function from your Twig (v3) templates.

1.0.0(4y ago)551.9k↑39.4%1MITPHPPHP &gt;=7.3

Since Jul 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/devknown/twig-import-function)[ Packagist](https://packagist.org/packages/devknown/twig-import-function)[ RSS](/packages/devknown-twig-import-function/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Twig v3 Import Function
=======================

[](#twig-v3-import-function)

[![Build Status](https://github.com/devknown/twig-import-function/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/devknown/twig-import-function/actions?query=branch%3Amain)[![License](https://camo.githubusercontent.com/c30135dcfabd936bdfc47c233452aebc116ad8ed7ac32e1dd743ef8aa9a15e85/68747470733a2f2f706f7365722e707567782e6f72672f6465766b6e6f776e2f747769672d696d706f72742d66756e6374696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/devknown/twig-import-function)

Call (almost) any PHP function from your Twig (v3) templates.

Requirements
------------

[](#requirements)

PHP 7.3 and later. Twig 3.x

Composer
--------

[](#composer)

You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:

```
composer require devknown/twig-import-function
```

To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):

```
require_once('vendor/autoload.php');
```

Manual Installation
-------------------

[](#manual-installation)

If you do not wish to use Composer, you can download and include the `ImportFunctionExtension.php` file.

```
require_once('./src/Devknown/Twig/Extension/ImportFunctionExtension.php');
```

Getting Started
---------------

[](#getting-started)

Simple usage looks like:

```
// 1. Setup twig 3.x
$loader = new \Twig\Loader\FilesystemLoader('/path/to/template');
$twig = new \Twig\Environment($loader);

// 2. Load extension
$extension = new \Devknown\Twig\Extension\ImportFunctionExtension();

// 3. Import a function
$extension->import('uniqid');

// -> Or multiple functions
function my_custom_function($name) {
    echo "Your name is: " . $name;
}
$extension->import(['uniqid', 'file_exists', 'my_custom_function']);
// Note: in this example, the 'my_custom_function..' must be accessible globally

// 4. Add extension
$twig->addExtension($extension);

// 5. Render as normal
echo $twig->render('home.html', ['the' => 'variables', 'go' => 'here']);
```

the template file `home.html` (/path/to/template/home.html) would look like:

```

    Hi, I am unique: {{ uniqid() }}.

    {{ my_custom_function('Devknown') }}

```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

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

Unknown

Total

1

Last Release

1463d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/718463eca5874773096a369e825077b35abd7af879c183b264bc38bb6a195a82?d=identicon)[devknown](/maintainers/devknown)

---

Top Contributors

[![devknown](https://avatars.githubusercontent.com/u/8023127?v=4)](https://github.com/devknown "devknown (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/devknown-twig-import-function/health.svg)

```
[![Health](https://phpackages.com/badges/devknown-twig-import-function/health.svg)](https://phpackages.com/packages/devknown-twig-import-function)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[mati365/ckeditor5-symfony

CKEditor 5 integration for Symfony

262.6k](/packages/mati365-ckeditor5-symfony)

PHPackages © 2026

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