latte-templates
Invoke before creating or modifying .latte files, even for single-line changes. Provides Latte syntax, tags, filters, n:attributes, layouts, template inheritance, AJAX snippets, extensions, and Nette integration. Also trigger when user mentions Latte by name.
What this skill does
## Latte Templating System
Latte is a secure templating engine with context-aware escaping, intuitive syntax, and powerful template inheritance.
```shell
composer require latte/latte
```
### Basic Syntax
```latte
{* this is a comment *}
<ul n:if="$items"> {* n:attribute *}
{foreach $items as $item} {* tag *}
<li>{$item|capitalize}</li> {* variable with filter *}
{/foreach}
</ul>
```
### Printing Variables
```latte
{$name} {* prints escaped variable *}
{$user->name} {* object property *}
{$items[0]} {* array access *}
{='hello'|upper} {* expression with filter *}
{$html|noescape} {* disable escaping (use carefully!) *}
```
Latte uses **context-aware escaping** — output adapts to where the variable is printed. In `<script>` context, arrays and objects are automatically serialized to JSON:
```latte
{* Arrays auto-serialize to JSON inside <script> *}
<script type="application/ld+json">{$schemaData}</script>
<script>
let config = {$config};
</script>
```
Never use `json_encode()` in PHP + `|noescape` for this — Latte handles serialization and escaping safely on its own.
### Filters
Filters modify output, written after `|`:
```latte
{$title|upper} {* HELLO *}
{$text|truncate:100} {* shortens to 100 chars *}
{$price|number:2} {* formats number *}
{$date|date:'j. n. Y'} {* formats date *}
{$name|lower|capitalize} {* chained filters *}
```
Common filters: `upper`, `lower`, `capitalize`, `truncate`, `number`, `date`, `noescape`, `escapeUrl`, `stripHtml`, `trim`, `replace`, `first`, `last`, `length`, `sort`, `reverse`
The filter `|` applies to the entire expression before it. Parentheses around PHP operators (like `??`) before a filter are unnecessary:
```latte
{$a ?? $b|texyLine|noescape} {* correct – filter applies to result of ?? *}
{($a ?? $b)|texyLine|noescape} {* redundant – parentheses change nothing *}
```
See [the complete filter reference](references/filters.md) for all available filters.
### n:attributes
Pair tags can be written as HTML attributes:
```latte
{* These are equivalent: *}
{if $condition}<div>...</div>{/if}
<div n:if="$condition">...</div>
{* Applies to element content only: *}
<div n:inner-foreach="$items as $item">...</div>
{* Applies to tag only (not content): *}
<a href={$url} n:tag-if="$url">Link</a>
```
### Conditions
```latte
{if $stock > 0}
In stock
{elseif $onWay}
On the way
{else}
Not available
{/if}
{ifset $user}...{/ifset} {* if variable exists *}
{* switch/case *}
{switch $type}
{case admin}Administrator
{case user}User
{default}Guest
{/switch}
```
### Loops
```latte
{foreach $items as $item}
{$item->name}
{/foreach}
{foreach $items as $key => $item}
{$key}: {$item}
{/foreach}
{* With else for empty arrays *}
{foreach $items as $item}
<li>{$item}</li>
{else}
<li>No items found</li>
{/foreach}
{* Iterator variable *}
{foreach $items as $item}
{$iterator->counter}. {$item} {* 1, 2, 3... *}
{if $iterator->first}First!{/if}
{if $iterator->last}Last!{/if}
{/foreach}
{* Helper tags *}
{foreach $items as $item}
{first}<ul>{/first}
<li>{$item}</li>
{last}</ul>{/last}
{sep}, {/sep} {* separator between items *}
{/foreach}
```
### Variables
```latte
{var $name = 'John'}
{var $items = [1, 2, 3]}
{default $lang = 'en'} {* only if not set *}
{capture $content}
<p>Captured HTML</p>
{/capture}
{$content}
```
### Template Inheritance
**Layout template (`@layout.latte`):**
```latte
<!DOCTYPE html>
<html>
<head>
<title>{block title}Default{/block}</title>
</head>
<body>
{block content}{/block}
</body>
</html>
```
**Child template:**
```latte
{layout '@layout.latte'}
{block title}My Page{/block}
{block content}
<h1>Welcome</h1>
<p>Content here</p>
{/block}
```
### Including Templates
```latte
{include 'header.latte'}
{include 'item.latte', item: $item, showPrice: true}
{include $dynamicTemplate}
```
### Blocks
```latte
{block sidebar}
<aside>Sidebar content</aside>
{/block}
{include sidebar} {* print block *}
{include sidebar from 'other.latte'} {* from another file *}
{* Reusable definitions with parameters *}
{define button, $text, $type = 'primary'}
<button class="btn btn-{$type}">{$text}</button>
{/define}
{include button, 'Submit'}
{include button, 'Cancel', 'secondary'}
```
### Common Tags Reference
| Tag | Description |
|-----|-------------|
| `{$var}` | Print escaped variable |
| `{if}...{/if}` | Condition |
| `{foreach}...{/foreach}` | Loop |
| `{var $x = ...}` | Create variable |
| `{include 'file'}` | Include template |
| `{block name}...{/block}` | Define block |
| `{layout 'file'}` | Extend layout |
| `{do expression}` | Execute without output |
| `{php expression}` | Execute PHP expression |
| `{dump $var}` | Debug dump (Tracy) |
See [the complete tag reference](references/tags.md) for all available tags.
### Smart HTML Attributes
```latte
{* null removes attribute *}
<div title={$title}>
{* boolean controls presence *}
<input type="checkbox" checked={$isChecked}>
{* arrays in class *}
<div class={['btn', active => $isActive]}>
{* arrays JSON-encoded in data- *}
<div data-config={[theme: dark, count: 5]}>
```
### n:class Helper
```latte
{foreach $items as $item}
<a n:class="$item->active ? active, $iterator->first ? first, item">
{$item->name}
</a>
{/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
### Passing Variables to Templates
The standard way is assigning to `$this->template`:
```php
$this->template->article = $this->articles->getById($id);
```
For properties that should always be available in templates, use the `#[TemplateVariable]` attribute (requires public or protected visibility) instead of repeating assignments in every action:
```php
use Nette\Application\Attributes\TemplateVariable;
class ArticlePresenter extends Nette\Application\UI\Presenter
{
#[TemplateVariable]
public string $siteName = 'My blog';
}
```
The property value is automatically passed as `$siteName` in every template. If you explicitly assign `$this->template->siteName` in an action, the explicit value wins.
### 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}
<h1>{$product->name}</h1>
{foreach $variants as $variant}
<div class="variant">{$variant->name} - {$variant->price}</div>
{/foreach}
```
### Nette-specific Tags
```latte
{* Links *}
<a n:href="Product:detail $id">Detail</a>
<a href={link Product:detail $id}>Detail</a>
<a href={plink //Product:detail $id}>Absolute</a>
{* Components *}
{control productForm}
{control dataGrid}
{* AJAX Snippets *}
{snippet items}
{foreach $items as $item}
<div>{$item->name}</div>
{/foreach}
{/Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.