mattdanger / volt-helpers
Useful additions to the Volt template engine
Installs: 19 713
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-11-06 23:48:52 UTC
README
Useful additions to the Volt template engine
Installing
Install using Composer:
{ "require": { "mattdanger/volt-helpers": "dev-master" } }
You'll also need to add each function to the Volt service:
$di->set('view', function () use ($config) { $view = new View(); // ... $view->registerEngines(array( '.volt' => function ($view, $di) use ($config) { $volt = new VoltEngine($view, $di); $volt->getCompiler()->addFunction('ordinal', function ($resolvedArgs, $expArgs) { return 'VoltHelpers\Helpers::ordinal(' . $resolvedArgs . ')'; }); $volt->getCompiler()->addFunction('strToCurrency', function ($resolvedArgs, $expArgs) { return 'VoltHelpers\Helpers::strToCurrency(' . $resolvedArgs . ')'; }); $volt->getCompiler()->addFunction('pluralize', function ($resolvedArgs, $expArgs) { return 'VoltHelpers\Helpers::pluralize(' . $resolvedArgs . ')'; }); $volt->getCompiler()->addFunction('paginationPath', function ($resolvedArgs, $expArgs) { return 'VoltHelpers\Helpers::paginationPath(' . $resolvedArgs . ')'; }); // ... return $volt; }, // ... )); return $view; });
Using Helpers
Here's a list of what's included:
ordinal($number)
Number ordinal service - returns 1st, 2nd, 10th, 43rd, 724th, etc.
strToCurrency($value)
Output a string in currency format
pluralize($count, $singular, $plural)
Pluralize string
paginationPath()
Returns a URL encoded string with current request params plus a param for current pagination page number.