Skip to content

Commit 485a244

Browse files
committed
latte: info about whitespace
1 parent 3e9c4f0 commit 485a244

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

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+
A co když tag není na řádku sám, ale je tam i další obsah? Bílé znaky před tagem pak patří *dovnitř* tagu:
244+
245+
```latte
246+
<div>
247+
{if $foo}hello{/if}
248+
</div>
249+
```
250+
251+
Odsazení je tedy fakticky uvnitř `{if}`: pokud je `$foo` false, nevypíše se nic – ani odsazení, ani prázdný řádek. Pokud je `$foo` 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+
What if a tag isn't alone on a line, but appears alongside other content? The whitespace before the tag then belongs *inside* the tag:
244+
245+
```latte
246+
<div>
247+
{if $foo}hello{/if}
248+
</div>
249+
```
250+
251+
The indentation is effectively inside `{if}`: when `$foo` is false, nothing is output – not even the indentation or a blank line. When `$foo` is 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)