Skip to content

Commit 338e78f

Browse files
committed
latte: info about whitespace
1 parent 2dccb9c commit 338e78f

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

latte/cs/syntax.texy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,39 @@ Uvnitř značek fungují PHP komentáře:
218218
```
219219

220220

221+
Řízení bílých znaků
222+
====================
223+
224+
Latte zachází s bílými znaky inteligentně. Kód můžete volně odsazovat pro čitelnost a výstup zůstane čistý. Když se tag objeví na řádku sám, celý řádek (odsazení i konec řádku) se z výstupu odstraní:
225+
226+
```latte
227+
<ul>
228+
{foreach $items as $item}
229+
<li>{$item}</li>
230+
{/foreach}
231+
</ul>
232+
```
233+
234+
Vypíše:
235+
236+
```html
237+
<ul>
238+
<li>foo</li>
239+
<li>bar</li>
240+
</ul>
241+
```
242+
243+
Navíc bílé znaky před tagem na řádku s obsahem logicky patří *dovnitř* tagu:
244+
245+
```latte
246+
<div>
247+
{if $foo}hello{/if}
248+
</div>
249+
```
250+
251+
Chová se to, jako by odsazení bylo uvnitř `{if}`: pokud je `$foo` false, nevypíše se nic, ani odsazení, ani prázdný řádek. Pokud je true, výstup přirozeně obsahuje odsazení. Prostě pište přehledně odsazené šablony a výstup bude vždy čistý.
252+
253+
221254
Syntaktický cukr
222255
================
223256

latte/en/syntax.texy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,39 @@ PHP comments work inside tags:
218218
```
219219

220220

221+
Whitespace Control
222+
==================
223+
224+
Latte handles whitespace intelligently. You can freely indent your code for readability, and the output stays clean. When a tag appears alone on a line, the entire line (indentation and newline) is removed from the output:
225+
226+
```latte
227+
<ul>
228+
{foreach $items as $item}
229+
<li>{$item}</li>
230+
{/foreach}
231+
</ul>
232+
```
233+
234+
Outputs:
235+
236+
```html
237+
<ul>
238+
<li>foo</li>
239+
<li>bar</li>
240+
</ul>
241+
```
242+
243+
Furthermore, whitespace before a tag on a line with content logically belongs *inside* the tag:
244+
245+
```latte
246+
<div>
247+
{if $foo}hello{/if}
248+
</div>
249+
```
250+
251+
This behaves as if the indentation were inside `{if}`: when `$foo` is false, nothing is output, not even the indentation or a blank line. When true, the output naturally includes the indentation. You simply write well-structured templates and the output is always clean.
252+
253+
221254
Syntactic Sugar
222255
===============
223256

0 commit comments

Comments
 (0)