Skip to content

Commit 04af29b

Browse files
committed
latte 3.1.2
1 parent 6ef7d5d commit 04af29b

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

latte/cs/filters.texy

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ V šablonách můžeme používat funkce, které pomáhají upravit nebo přefor
1010
| `breakLines` | [Před konce řádku přidá HTML odřádkování |#breakLines]
1111
| `bytes` | [formátuje velikost v bajtech |#bytes]
1212
| `clamp` | [ohraničí hodnotu do daného rozsahu |#clamp]
13+
| `column` | [extrahuje jeden sloupec z pole |#column]
14+
| `commas` | [spojí pole čárkami |#commas]
1315
| `dataStream` | [konverze pro Data URI protokol |#dataStream]
1416
| `date` | [formátuje datum a čas |#date]
1517
| `explode` | [rozdělí řetězec na pole podle oddělovače |#explode]
@@ -259,6 +261,50 @@ Ohraničí hodnotu do daného inkluzivního rozsahu min a max.
259261
Existuje také jako [funkce |functions#clamp].
260262

261263

264+
column(string|int|null $columnKey, string|int|null $indexKey=null) .[filter]{data-version:3.1.2}
265+
------------------------------------------------------------------------------------------------
266+
Vybere hodnoty konkrétního klíče z každého prvku pole. Když máte pole záznamů (např. uživatelů, produktů), tento filtr vybere jen jedno pole z každého záznamu.
267+
268+
```latte
269+
{var $users = [
270+
[id: 30, name: 'John', age: 30],
271+
[id: 32, name: 'Jane', age: 25],
272+
[id: 33, age: 35],
273+
]}
274+
275+
{$users|column: 'name'}
276+
{* vrátí ['John', 'Jane'] *}
277+
278+
{$users|column: 'name', 'id'}
279+
{* vrátí [30 => 'John', 32 => 'Jane'] *}
280+
```
281+
282+
Pokud předáte `null` jako klíč sloupce, vrátí celé pole (užitečné, když chcete pouze přeindexovat podle `$indexKey`).
283+
284+
285+
commas(?string $lastGlue=null) .[filter]{data-version:3.1.2}
286+
------------------------------------------------------------
287+
Spojí prvky pole čárkou a mezerou (`', '`). Jedná se o pohodlnou zkratku pro běžný případ výpisu položek v čitelné podobě.
288+
289+
```latte
290+
{var $items = ['jablka', 'pomeranče', 'banány']}
291+
{$items|commas}
292+
{* vypíše 'jablka, pomeranče, banány' *}
293+
```
294+
295+
Volitelně můžete zadat vlastní oddělovač pro poslední dvojici položek:
296+
297+
```latte
298+
{$items|commas: ' a '}
299+
{* vypíše 'jablka, pomeranče a banány' *}
300+
301+
{=['PHP', 'JavaScript', 'Python']|commas: ', nebo '}
302+
{* vypíše 'PHP, JavaScript, nebo Python' *}
303+
```
304+
305+
Viz také [#implode].
306+
307+
262308
dataStream(string $mimetype=detect) .[filter]
263309
---------------------------------------------
264310
Konvertuje obsah do data URI scheme. Pomocí něj lze do HTML nebo CSS vkládat obrázky bez nutnosti linkovat externí soubory.
@@ -407,6 +453,8 @@ Můžete také použít alias `join`:
407453
{=[1, 2, 3]|join} {* vypíše '123' *}
408454
```
409455

456+
Viz také [#commas], [#explode].
457+
410458

411459
indent(int $level=1, string $char="\t") .[filter]
412460
-------------------------------------------------

latte/en/filters.texy

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ In templates, we can use functions that help modify or reformat data into its fi
1010
| `breakLines` | [Inserts HTML line breaks before all newlines |#breakLines]
1111
| `bytes` | [formats size in bytes |#bytes]
1212
| `clamp` | [clamps a value to the given range |#clamp]
13+
| `column` | [extracts a single column from an array |#column]
14+
| `commas` | [joins an array with commas |#commas]
1315
| `dataStream` | [Data URI protocol conversion |#dataStream]
1416
| `date` | [formats the date and time |#date]
1517
| `explode` | [splits a string into an array by a delimiter |#explode]
@@ -259,6 +261,50 @@ Clamps a value to the given inclusive range of min and max.
259261
Also exists as a [function |functions#clamp].
260262

261263

264+
column(string|int|null $columnKey, string|int|null $indexKey=null) .[filter]{data-version:3.1.2}
265+
------------------------------------------------------------------------------------------------
266+
Extracts values from a specific key from each element of an array. When you have an array of objects, this filter picks out just one property value.
267+
268+
```latte
269+
{var $users = [
270+
[id: 30, name: 'John', age: 30],
271+
[id: 32, name: 'Jane', age: 25],
272+
[id: 33, age: 35],
273+
]}
274+
275+
{$users|column: 'name'}
276+
{* returns ['John', 'Jane'] *}
277+
278+
{$users|column: 'name', 'id'}
279+
{* returns [30 => 'John', 32 => 'Jane'] *}
280+
```
281+
282+
If you pass `null` as the column key, it returns the entire array (useful when you only want to re-index by the `$indexKey`).
283+
284+
285+
commas(?string $lastGlue=null) .[filter]{data-version:3.1.2}
286+
------------------------------------------------------------
287+
Joins array elements with a comma and space (`', '`). This is a convenient shortcut for the common use case of listing items in a human-readable format.
288+
289+
```latte
290+
{var $items = ['apples', 'oranges', 'bananas']}
291+
{$items|commas}
292+
{* outputs 'apples, oranges, bananas' *}
293+
```
294+
295+
You can optionally provide a custom separator for the last pair of items:
296+
297+
```latte
298+
{$items|commas: ' and '}
299+
{* outputs 'apples, oranges and bananas' *}
300+
301+
{=['PHP', 'JavaScript', 'Python']|commas: ', or '}
302+
{* outputs 'PHP, JavaScript, or Python' *}
303+
```
304+
305+
See also [#implode].
306+
307+
262308
dataStream(string $mimetype='detect') .[filter]
263309
-----------------------------------------------
264310
Converts content to the data URI scheme. This allows embedding images into HTML or CSS without needing to link external files.
@@ -407,6 +453,8 @@ You can also use the alias `join`:
407453
{=[1, 2, 3]|join} {* outputs '123' *}
408454
```
409455

456+
See also [#commas], [#explode].
457+
410458

411459
indent(int $level=1, string $char="\t") .[filter]
412460
-------------------------------------------------

0 commit comments

Comments
 (0)