Skip to content

Commit

Permalink
latte 3.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 14, 2024
1 parent d912e81 commit 4f981ff
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 8 deletions.
53 changes: 50 additions & 3 deletions latte/cs/filters.texy
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Vypíše:
</table>
```

Viz také [#group] a značka [iterateWhile|tags#iterateWhile].


breakLines .[filter]
--------------------
Expand Down Expand Up @@ -331,6 +333,25 @@ Převede první písmeno na velká. Vyžaduje PHP rozšíření `mbstring`.
Viz také [#capitalize], [#lower], [#upper].


group(string|int|\Closure by): array .[filter]{data-version:3.0.16}
-------------------------------------------------------------------
Filtr seskupí data podle různých kritérií.

V tomto příkladu se řádky v tabulce seskupují podle sloupce `categoryId`. Výstupem je pole polí, kde klíčem je hodnota ve sloupci `categoryId`. [Přečtěte si podrobný návod|cookbook/grouping].

```latte
{foreach ($table|group: 'categoryId') as $categoryId => $items}
<ul>
{foreach $items as $item}
<li>{$item->name}</li>
{/foreach}
</ul>
{/foreach}
```

Viz také [#batch], funkce [group|functions#group] a značka [iterateWhile|tags#iterateWhile].


implode(string glue = '') .[filter]
-----------------------------------
Vrátí řetězec, který je zřetězením položek sekvence. Alias pro `join`.
Expand Down Expand Up @@ -594,7 +615,7 @@ Ve výchozím nastavení filtr změní pořadí a resetuje celočíselného klí

sort(?Closure comparison, string|int|\Closure|null by=null, string|int|\Closure|bool byKey=false) .[filter]
-----------------------------------------------------------------------------------------------------------
Filtr, který seřadí pole. Zachovává asociaci s klíčí.
Filtr slouží k seřazení prvků v poli nebo iterátoru, přičemž zachovává asociační klíče:

```latte
{foreach ($names|sort) as $name}
Expand All @@ -610,12 +631,38 @@ Filtr, který seřadí pole. Zachovává asociaci s klíčí.
{/foreach}
```

Jako parametr lze předat vlastní porovnávací funkci:
Můžete specifikovat vlastní porovnávací funkci pro řazení (příklad ukazuje, jak obrátit řazení od největší po nejmenší):

```latte
{var $reverted = ($names|sort: fn($a, $b) => $b <=> $a)}
```

Filtr `|sort` také umožňuje řadit prvky podle klíčů:

```latte
{foreach ($names|sort: byKey: true) as $name}
...
{/foreach}
```

Pokud potřebujete seřadit tabulku podle konkrétního sloupce, můžete použít parametr `by`. Hodnota `'name'` v ukázce určuje, že se bude řadit podle `$row->name` nebo `$row['name']`, v závislosti na tom, zda je `$row` pole nebo objekt:

```latte
{var $sorted = ($names|sort: fn($a, $b) => $b <=> $a)}
{foreach ($table|sort: by: 'name') as $row}
{$row->name}
{/foreach}
```

Můžete také definovat callback funkci, která určí hodnotu, podle které se má řadit:

```latte
{foreach ($table|sort: by: fn($row) => $row->category->name) as $row}
{$row->name}
{/foreach}
```

Stejným způsobem lze využít i parametr `byKey`.


spaceless .[filter]
-------------------
Expand Down
19 changes: 19 additions & 0 deletions latte/cs/functions.texy
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ Vrací první prvek pole nebo znak řetězce:
Viz také [#last], [filtr first|filters#first].


group(iterable $data, string|int|\Closure $by): array .[method]{data-version:3.0.16}
------------------------------------------------------------------------------------
Funkce seskupí data podle různých kritérií.

V tomto příkladu se řádky v tabulce seskupují podle sloupce `categoryId`. Výstupem je pole polí, kde klíčem je hodnota ve sloupci `categoryId`. [Přečtěte si podrobný návod|cookbook/grouping].

```latte
{foreach group($table, 'categoryId') as $categoryId => $items}
<ul>
{foreach $items as $item}
<li>{$item->name}</li>
{/foreach}
</ul>
{/foreach}
```

Viz také filtr [group|filters#group].


hasBlock(string $name): bool .[method]{data-version:3.0.10}
-----------------------------------------------------------
Zjistí, zda blok uvedeného jména existuje:
Expand Down
4 changes: 3 additions & 1 deletion latte/cs/tags.texy
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ To je docela praktické, že?
`{iterateWhile}`
----------------

Zjednodušuje seskupování lineárních dat během iterování v cyklu foreach tím, že iteraci provádí ve vnořené smyčce, dokud je splněná podmínka. [Přečtěte si návod|cookbook/iteratewhile].
Zjednodušuje seskupování lineárních dat během iterování v cyklu foreach tím, že iteraci provádí ve vnořené smyčce, dokud je splněná podmínka. [Přečtěte si podrobný návod|cookbook/grouping].

Může také elegantně nahradit `{first}` a `{last}` v příkladu výše:

Expand All @@ -501,6 +501,8 @@ Může také elegantně nahradit `{first}` a `{last}` v příkladu výše:
{/foreach}
```

Viz také filtry [batch|filters#batch] a [group|filters#group].


`{for}`
-------
Expand Down
53 changes: 50 additions & 3 deletions latte/en/filters.texy
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Prints:
</table>
```

See also [group |#group] and [iterateWhile |tags#iterateWhile] tag.


breakLines .[filter]
--------------------
Expand Down Expand Up @@ -331,6 +333,25 @@ Converts a first letter of value to uppercase. Requires PHP extension `mbstring`
See also [#capitalize], [#lower], [#upper].


group(string|int|\Closure by): array .[filter]{data-version:3.0.16}
-------------------------------------------------------------------
The filter groups the data according to different criteria.

In this example, the rows in the table are grouped by the column `categoryId`. The output is an array of arrays where the key is the value in the column `categoryId`. Read the [detailed instructions |cookbook/grouping].

```latte
{foreach ($table|group: 'categoryId') as $categoryId => $items}
<ul>
{foreach $items as $item}
<li>{$item->name}</li>
{/foreach}
</ul>
{/foreach}
```

See also [batch |#batch], the [group |functions#group] function, and the [iterateWhile |tags#iterateWhile] tag.


implode(string glue = '') .[filter]
-----------------------------------
Return a string which is the concatenation of the strings in the array. Alias for `join`.
Expand Down Expand Up @@ -594,7 +615,7 @@ Filter will reorder and reset the integer array keys by default. This behaviour

sort(?Closure comparison, string|int|\Closure|null by=null, string|int|\Closure|bool byKey=false) .[filter]
-----------------------------------------------------------------------------------------------------------
Filter that sorts an array and maintain index association.
The filter is used to sort the elements in an array or iterator while preserving the association keys:

```latte
{foreach ($names|sort) as $name}
Expand All @@ -610,12 +631,38 @@ Array sorted in reverse order.
{/foreach}
```

You can pass your own comparison function as a parameter:
You can specify a custom comparison function for sorting (the example shows how to reverse the sort from largest to smallest):

```latte
{var $reverted = ($names|sort: fn($a, $b) => $b <=> $a)}
```

The `|sort` filter also allows you to sort elements by key:

```latte
{foreach ($names|sort: byKey: true) as $name}
...
{/foreach}
```

If you need to sort the table by a specific column, you can use the `by` parameter. The `'name'` value in the example specifies that it will be sorted by `$row->name` or `$row['name']`, depending on whether `$row` is an array or an object:

```latte
{var $sorted = ($names|sort: fn($a, $b) => $b <=> $a)}
{foreach ($table|sort: by: 'name') as $row}
{$row->name}
{/foreach}
```

You can also define a callback function that determines the value to sort by:

```latte
{foreach ($table|sort: by: fn($row) => $row->category->name) as $row}
{$row->name}
{/foreach}
```

The `byKey` parameter can be used in the same way.


spaceless .[filter]
--------------------
Expand Down
19 changes: 19 additions & 0 deletions latte/en/functions.texy
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ Returns the first element of array or character of string:
See also [#last], [filter first|filters#first].


group(iterable $data, string|int|\Closure $by): array .[method]{data-version:3.0.16}
------------------------------------------------------------------------------------
This function groups data according to different criteria.

In this example, the rows in the table are grouped by the column `categoryId`. The output is an array of fields where the key is the value in the column `categoryId`. Read the [detailed instructions |cookbook/grouping].

```latte
{foreach group($table, 'categoryId') as $categoryId => $items}
<ul>
{foreach $items as $item}
<li>{$item->name}</li>
{/foreach}
</ul>
{/foreach}
```

See also filter [group |filters#group].


hasBlock(string $name): bool .[method]{data-version:3.0.10}
-----------------------------------------------------------
Checks if the block of the specified name exists:
Expand Down
4 changes: 3 additions & 1 deletion latte/en/tags.texy
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ That's pretty practical, isn't it?
`{iterateWhile}`
----------------

It simplifies the grouping of linear data during iteration in a foreach loop by performing the iteration in a nested loop as long as the condition is met. [Read instructions in cookbook|cookbook/iteratewhile].
Simplifies the grouping of linear data during iteration in a foreach loop by iterating in a nested loop until a condition is satisfied. [Read the detailed instructions |cookbook/grouping].

It can also elegantly replace `{first}` and `{last}` in the example above:

Expand All @@ -501,6 +501,8 @@ It can also elegantly replace `{first}` and `{last}` in the example above:
{/foreach}
```

See also [batch |filters#batch] and [group |filters#group] filters.


`{for}`
-------
Expand Down

0 comments on commit 4f981ff

Please sign in to comment.