Latest release: v0.3

Latte

Content

Version(s) Extension

This extension adds 3 macros: {rev}, {build}, {v}.

Install

extensions:
    version: Contributte\Latte\DI\VersionExtension
1
2

Configuration

version:
    rev: e3203c85a9b84ee866132f371ba0b238b6a5b245
    build: 2016
    v: 2.12
1
2
3
4

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
1
2
3
4
5
<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}">
1
2
3

Filters Extension

Install filters by single extension and simple FiltersProvider implementation.

Installation

extensions:
    filters: Contributte\Latte\DI\FiltersExtension
1
2

Usage

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);
			},
		];
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

After that, add you filters provider as a service to your config (neon) file.

services:
    - MyFilters
1
2

That's all.

RuntimeFilters

Filectime

<link rel="stylesheet" href="{=$basePath/assets/theme.css|filectime}">
1
<link rel="stylesheet" href=/assets/theme.css?v=123456789">
1

Email

{var $email => 'my@email.cz'}

This is my email: {$email|email}.
This is my email: {="my@email.cz"|email}.
1
2
3
4
This is my email: <a href="mailto: my[at]email.org">my[at]email.org</a>
1

Formatters

NumberFormatter

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])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

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)