Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umpirsky/twig-php-function
Call (almost) any PHP function from your Twig templates.
https://github.com/umpirsky/twig-php-function
Last synced: 2 days ago
JSON representation
Call (almost) any PHP function from your Twig templates.
- Host: GitHub
- URL: https://github.com/umpirsky/twig-php-function
- Owner: umpirsky
- License: mit
- Created: 2014-12-09T17:00:31.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-20T16:51:21.000Z (8 months ago)
- Last Synced: 2024-05-21T07:03:59.993Z (6 months ago)
- Language: PHP
- Size: 29.3 KB
- Stars: 60
- Watchers: 6
- Forks: 20
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
symfony upgrade fixer •
twig gettext extractor •
wisdom •
centipede •
permissions handler •
extraload •
gravatar •
locurro •
country list •
transliterator# Twig PHP Function [![Build Status](https://travis-ci.org/umpirsky/twig-php-function.svg?branch=master)](https://travis-ci.org/umpirsky/twig-php-function)
Call (almost) any PHP function from your Twig templates.
## Usage
After [registering](http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension) `PhpFunctionExtension` call PHP functions from your templates like this:
```twig
Hi, I am unique: {{ uniqid() }}.And {{ floor(7.7) }} is floor of 7.7.
```## Extend
You can control allowed PHP functions by adding new ones like this:
```php
$extension = new Umpirsky\Twig\Extension\PhpFunctionExtension();
$extension->allowFunction('hash_hmac');
```or restrict what functions are allowed like this:
```php
$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.