PHPackages                             macwinnie/twig-php-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. macwinnie/twig-php-function

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

macwinnie/twig-php-function
===========================

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

1.0.0(3y ago)027MITPHPPHP ^7.4 || ^8.0

Since Apr 17Pushed 3y agoCompare

[ Source](https://github.com/macwinnie/twig-php-function)[ Packagist](https://packagist.org/packages/macwinnie/twig-php-function)[ RSS](/packages/macwinnie-twig-php-function/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

###  [ ![](https://camo.githubusercontent.com/4acdbd12ae1b9a9539be7b30f8cef6cd9678ccb45500067152e333743632afd8/68747470733a2f2f6661726d322e737461746963666c69636b722e636f6d2f313730392f32353039383532363838345f616534643530343635665f6f5f642e706e67) ](https://github.com/umpirsky)

[](#----------------)

 [symfony upgrade fixer](https://github.com/umpirsky/Symfony-Upgrade-Fixer) • [twig gettext extractor](https://github.com/umpirsky/Twig-Gettext-Extractor) • [wisdom](https://github.com/umpirsky/wisdom) • [centipede](https://github.com/umpirsky/centipede) • [permissions handler](https://github.com/umpirsky/PermissionsHandler) • [extraload](https://github.com/umpirsky/Extraload) • [gravatar](https://github.com/umpirsky/Gravatar) • [locurro](https://github.com/umpirsky/locurro) • [country list](https://github.com/umpirsky/country-list) • [transliterator](https://github.com/umpirsky/Transliterator)

Twig PHP Function [![Build Status](https://camo.githubusercontent.com/ea4f46dd43cdc918661806b00b0f3c3700db1281bdd5a08b1817e96507a95608/68747470733a2f2f7472617669732d63692e6f72672f756d706972736b792f747769672d7068702d66756e6374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/umpirsky/twig-php-function)
===============================================================================================================================================================================================================================================================================================================================

[](#twig-php-function-)

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

Usage
-----

[](#usage)

After [registering](http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension) `PhpFunctionExtension` call PHP functions from your templates like this:

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

And {{ floor(7.7) }} is floor of 7.7.
```

Extend
------

[](#extend)

You can control allowed PHP functions by adding new ones like this:

```
$extension = new Umpirsky\Twig\Extension\PhpFunctionExtension();
$extension->allowFunction('hash_hmac');
```

or restrict what functions are allowed like this:

```
$extension = new Umpirsky\Twig\Extension\PhpFunctionExtension(['floor', 'ceil']);
```

If you think that some function should be allowed/not allowed, feel free to [raise issue](https://github.com/umpirsky/twig-php-function/issues/new) or submit a pull request.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70% 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

1126d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/06148942cbb815f08bd44856cdc26cc63446ef01adf1f207100ae76965c017d6?d=identicon)[macwinnie](/maintainers/macwinnie)

---

Top Contributors

[![umpirsky](https://avatars.githubusercontent.com/u/208957?v=4)](https://github.com/umpirsky "umpirsky (14 commits)")[![macwinnie](https://avatars.githubusercontent.com/u/1001936?v=4)](https://github.com/macwinnie "macwinnie (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![josevieirame](https://avatars.githubusercontent.com/u/1133889?v=4)](https://github.com/josevieirame "josevieirame (1 commits)")[![lyrixx](https://avatars.githubusercontent.com/u/408368?v=4)](https://github.com/lyrixx "lyrixx (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/macwinnie-twig-php-function/health.svg)

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

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36663.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

21946.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21814.8M162](/packages/symfony-ux-twig-component)

PHPackages © 2026

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