```
### n:class Helper
```latte
{foreach $items as $item}
{$item->name}
{/foreach}
```
---
## Latte in Nette Applications
### Template Organization Strategy
**Keep templates with presenters:**
```
Product/
├── ProductPresenter.php
├── default.latte
├── edit.latte
└── detail.latte
```
**Layout placement follows presenter organization:**
```
Admin/
├── @layout.latte ← Admin-wide layout
├── Auth/
│ ├── @layout.latte ← Auth-specific layout
│ └── AuthPresenter.php
└── Catalog/
└── Product/
├── ProductPresenter.php
└── edit.latte
```
### Template Partial Patterns
**Shared template parts use @ prefix:**
- `@layout.latte` - layout templates
- `@form.latte` - reusable form structures
- `@item.latte` - list item templates
### Template Class Strategy
**Create template classes for complex presenters:**
```php
/**
* @property-read ProductTemplate $template
*/
class ProductPresenter extends BasePresenter
{
}
class ProductTemplate extends Nette\Bridges\ApplicationLatte\Template
{
public ProductRow $product;
public array $variants;
public ?CategoryRow $category;
}
```
**When to use template classes:**
- Presenters with 5+ template variables
- Complex data structures passed to templates
- When you want full IDE support in templates
**Template Type Declaration:**
```latte
{templateType App\Presentation\Product\ProductTemplate}
{$product->name}
{foreach $variants as $variant}
{$variant->name} - {$variant->price}
{/foreach}
```
### Nette-specific Tags
```latte
{* Links *}
Detail
Detail
Absolute
{* Components *}
{control productForm}
{control dataGrid}
{* AJAX Snippets *}
{snippet items}
{foreach $items as $item}
{$item->name}
{/foreach}
{/snippet}
{* Forms *}
{form loginForm}
{label username}{input username}
{label password}{input password}
{input submit}
{/form}
{* Assets (Nette Assets) *}
{asset 'admin.js'}
{asset 'front.css'}
```
### Extension and Customization
**Create single extension for entire application:**
```php
final class LatteExtension extends Latte\Extension
{
public function getFilters(): array
{
return [
'money' => fn($amount) => number_format($amount, 0, ',', ' ') . ' Kč',
];
}
public function getFunctions(): array
{
return [
'canEdit' => fn($entity) => $this->user->isAllowed($entity, 'edit'),
];
}
}
```
**Register in config:**
```neon
latte:
extensions:
- App\Presentation\Accessory\LatteExtension
```
### Latte Configuration
```neon
latte:
strictParsing: yes
locale: cs
```
### Anti-Patterns to Avoid
- **Don't put business logic in templates** - templates display data, don't process it
- **Don't create deep template hierarchies** - prefer composition over inheritance
- **Don't duplicate template code** - extract to partials or components
---
## Online Documentation
For detailed information beyond this reference, fetch from latte.nette.org:
- [Syntax](https://latte.nette.org/en/syntax) - complete syntax guide with examples
- [Tags](https://latte.nette.org/en/tags) - all available tags in detail
- [Filters](https://latte.nette.org/en/filters) - all filters with usage examples
- [Template Inheritance](https://latte.nette.org/en/template-inheritance) - layouts, blocks, embed
- [Functions](https://latte.nette.org/en/functions) - built-in functions
- [Extending Latte](https://latte.nette.org/en/extending-latte) - custom tags, filters, extensions
- [Type System](https://latte.nette.org/en/type-system) - template types and IDE support
- [Safety First](https://latte.nette.org/en/safety-first) - security and escaping
When you need more details about a specific Latte feature not covered in this skill, use WebFetch to retrieve information from these URLs.