Extra contribution to nette/latte
.
- Setup
- VersionExtension - revision macros for assets
- FiltersExtension - install filters easily
- RuntimeFilters - collection of prepared filters
- Formatters - collection of prepared formatters
composer require contributte/latte
This extension adds 3 macros: {rev}
, {build}
, {v}
.
extensions:
version: Contributte\Latte\DI\VersionExtension
version:
rev: e3203c85a9b84ee866132f371ba0b238b6a5b245
build: 2016
v: 2.12
Alternatively, you can use the generated
property. It generates rev/build/v for each container compilation, i.e. each time in the debug mode and once in the production mode. Very useful.
version:
generated: %debugMode%
# rev: auto-generated
# build: auto-generated
# v: auto-generated
<link rel="stylesheet" href="{$basePath}/assets/theme.css?v={rev}">
<link rel="stylesheet" href="{$basePath}/assets/theme.css?v={build}">
<link rel="stylesheet" href="{$basePath}/assets/theme.css?v={v}">
Install filters by single extension and simple FiltersProvider
implementation.
extensions:
filters: Contributte\Latte\DI\FiltersExtension
First of all, you have to define your own filters provider. It's key => value
, that means name => callback
array.
use Contributte\Latte\Filters\FiltersProvider;
final class MyFilters implements FiltersProvider
{
/**
* @return callable[]
*/
public function getFilters(): array
{
return [
'say' => function ($hi) {
return sprintf('Hi %s!', $hi);
},
];
}
}
After that, add you filters provider as a service to your config (neon) file.
services:
- MyFilters
That's all.
<link rel="stylesheet" href="{=$basePath/assets/theme.css|filectime}">
<link rel="stylesheet" href=/assets/theme.css?v=123456789">
{var $email = "my@email.net"}
{$email|email:"javascript"}
{$email|email:"javascript_charcode"}
{$email|email:"hex"|noescape}
{$email|email:"javascript":"link to my email here"}
{$email|email:"drupal"}
{$email|email:"texy"}
This is my email: <a href="mailto: my[at]email.org">my[at]email.org</a>
- javascript
- javascript_charcode
- hex
- drupal
- texy
services:
nette.latteFactory:
setup:
- addFilter('email', ['Contributte\Latte\Filters\EmailFilter', 'filter'])
Create link to gravatar image
<img src="{lorem@ipsum.com|gravatar}"/>
<img src="https://www.gravatar.com/avatar/067398c3f23785981cd8672e21643405.jpg?default=retro&size=80"/>
<img src="{lorem@ipsum.com|gravatar:[size=>48, style=>robohash, format=>png]}"/>
<img src="https://www.gravatar.com/avatar/067398c3f23785981cd8672e21643405.png?default=robohash&size=48"/>
Number formatter is simple wrapper class over the number_format
function.
services:
formatter.money:
# with defined prefix
class: Contributte\Latte\Formatters\NumberFormatter('Kč')
formatter.weight:
# with defined prefix and suffix
class: Contributte\Latte\Formatters\NumberFormatter('kg', '~')
setup:
- setThousands('')
- setDecimals(0)
nette.latteFactory:
setup:
# used as latte filter
- addFilter(money, [@formatter.number, format])
- addFilter(weight, [@formatter.weight, format])
Methods:
setDecimals(int $decimals)
setPoint(string $separator)
setThousands(string $separator)
setZeros(bool $display)
setSuffix(string $suffix)
setPrefix(string $prefix)
setString(bool $throw)
setSpaces(bool $display)
setCallback(callable $callback)