<?php
protected function beforeRender()
{
$this->template->addFilter('abs', function ($number) {
return abs($number);
});
}
<?php
// jako cela trida, bez zavislosti
namespace petrjirasek\Latte;
use Nette\Object;
class AbsFilter extends Object
{
/**
* @param int $number
* @return int
*/
public function __invoke($number)
{
return abs($number);
}
}
// PRESENTER
use petrjirasek\Latte\AbsFilter;
protected function beforeRender()
{
$this->template->addFilter('abs', new AbsFilter);
}
<?php
// se zavislostmi
use petrjirasek\Latte\AbsFilter;
/** @var AbsFilter @inject */
public $absFilter;
protected function beforeRender()
{
$this->template->addFilter('abs', $this->absFilter);
}