Skip to content
Skills Library
Programming · Building & coding

nette-components

/nette-components

Invoke before writing or modifying a Nette component (Control), a component factory or a signal handler, and before any AJAX/snippet code. Use when working with createComponent<Name>(), $this['name'], handle<Signal>() methods, signal links (n:href="click!", link('click')), {plink} in a component template, persistent parameters (#[Persistent]) and persistent components, redrawControl()/isControlInvalid(), {snippet} and {snippetArea}, dynamic snippets, isAjax() and $this->payload, Multiplier, or the component tree (getComponents(), getComponentTree(), monitor(), lookup(), $onAnchor). Also trigge

Author
nette ↗
Licence
MIT
Last repository change
25.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Invoke before writing or modifying a Nette component (Control), a component factory or a signal handler, and before any AJAX/snippet code. Use when working with createComponent<Name>(), $this['name'], handle<Signal>() methods, signal links (n:href="click!", link('click')), {plink} in a component template, persistent parameters (#[Persistent]) and persistent components, redrawControl()/isControlInvalid(), {snippet} and {snippetArea}, dynamic snippets, isAjax() and $this->payload, Multiplier, or the component tree (getComponents(), getComponentTree(), monitor(), lookup(), $onAnchor). Also trigge

Triggers from the description

nameclick!click
Original author description

Invoke before writing or modifying a Nette component (Control), a component factory or a signal handler, and before any AJAX/snippet code. Use when working with createComponent<Name>(), $this['name'], handle<Signal>() methods, signal links (n:href="click!", link('click')), {plink} in a component template, persistent parameters (#[Persistent]) and persistent components, redrawControl()/isControlInvalid(), {snippet} and {snippetArea}, dynamic snippets, isAjax() and $this->payload, Multiplier, or the component tree (getComponents(), getComponentTree(), monitor(), lookup(), $onAnchor). Also trigge

How it works

  1. Nette Components, Signals and Snippets
Original SKILL.md headings · 217 lines, 1,268 words
SKILL.md preview
---
name: nette-components
description: Invoke before writing or modifying a Nette component (Control), a component factory or a signal handler, and before any AJAX/snippet code. Use when working with createComponent<Name>(), $this['name'], handle<Signal>() methods, signal links (n:href="click!", link('click')), {plink} in a component template, persistent parameters (#[Persistent]) and persistent components, redrawControl()/isControlInvalid(), {snippet} and {snippetArea}, dynamic snippets, isAjax() and $this->payload, Multiplier, or the component tree (getComponents(), getComponentTree(), monitor(), lookup(), $onAnchor). Also trigger for "snippet is not redrawing", BadSignalException, or "how do I do AJAX in Nette".
---

## Nette Components, Signals and Snippets

A component is a descendant of `Nette\Application\UI\Control`, and the presenter is itself a `Control`
(`ComponentModel\Component` -> `Container` -> `UI\Component` -> `UI\Control` -> `UI\Presenter`), so
everything below applies to both. Related skills: **nette-forms** (controls, validation, `onSuccess`),
**nette-architecture** (where components live), **latte-templates** (`{control}`/`{snippet}` syntax),
**nette-configuration** (generated factories), **frontend-development** (Naja on the JS side).

### Component Factories

Any container (presenter or control) creates children lazily through `createComponent<Name>()`:

```php
protected function createComponentPoll(): PollControl
{
	return new PollControl($this->items);
}
```

The factory is never called directly. It fires on first access – `$this->getComponent('poll')` or the
equivalent `$this['poll']` (the `ComponentModel\ArrayAccess` trait), which is what `{control poll}` does.
An untouched component is never built.

- **The name starts with a lowercase letter.** `Container::createComponent()` requires
  `ucfirst($name) !== $name`, so asking for `Poll` never reaches `createComponentPoll()`.
- The factory receives the name as its first argument, and may either return the component or add it
  itself with `addComponent()`; doing neither throws `Nette\UnexpectedValueException`.
- Names match `#^[a-zA-Z0-9_]+$#D` – **no hyphen in a name**, `-` is the tree separator:
  `$this['cart-form']` means "child `form` of child `cart`", nesting to any depth.
- Not presenter-only: a `Control` defines `createComponent<Name>()` for its own children the same way.
- For components with dependencies, inject a factory (a class or a DI-generated interface) and call it
  from `createComponent<Name>()` – see **nette-configuration** for `implement:`.

### Signals

A signal performs an action on the *current* page. It calls `handle<Signal>()` on the component
addressed by the `do` query parameter (`?do=cart-remove`); matching is case-insensitive.

```php
public function handleDelete(int $id): void   // ?do=delete&id=…
{
	$this->facade->delete($id);
	$this->redirect('this');
}
```

**Where signals run** – **after** the action phase and canonicalization, **before** any render
method, not "in the action phase" (the full lifecycle order is in **nette-architecture**).
Consequence: a handler can prepare data that `render<View>()` then respects
(`if (!isset($this->template->articles)) …`).

- A signal cannot target another presenter or action; it re-runs the current request plus the handler.
  A missing handler throws `BadSignalException` (403 page).
- Signal parameters come from the URL **and from the POST body**, but a URL parameter of the same name
  wins. They share one namespace with action and persistent parameters.
- **A form submit is not a signal.** `UI\Form::signalReceived()` accepts only the signal `submit`
  and turns it into `onSubmit`/`onSuccess`; any other signal name on a form throws `BadSignalException`.
  Never write `handleSubmit()` for a form – put the logic in an `onSuccess` handler (see **nette-forms**).

### Links Inside a Component

In a component template, `n:href`, `{link}` and `$this->link()`/`$this->redirect()` **always mean a
signal of that component**, with or without `!` – `LinkGenerator` switches to signal mode as soon as the
link source is not a `Presenter`.

```latte
{* inside a component template *}
<a n:href="click!">signal</a>          {* the ! is optional here *}
<a n:href="subcomponent:click!">signal of a child</a>
<a href={plink Home:default}>presenter link</a>
```

`{plink}` = **presenter link**: it compiles to `$this->global->uiPresenter->link(...)`, where `{link}`
and `n:href` compile to `$this->global->uiControl->link(...)`. It is *not* "absolute" and *not*
"persistent" – an absolute URL comes from the `//` prefix, which works with `{link}` too. In PHP the
equivalent is `$this->getPresenter()->link('Home:default')`.

The only non-signal destination inside a component is `'this'` (current presenter + action):
`$this->redirect('this')`. Arguments cannot be passed to `this!`.

### Persistent Parameters

A persistent parameter survives across requests in the URL, automatically, including links generated by
other components on the page.

```php
use Nette\Application\Attributes\Persistent;

class ItemList extends Control
{
	#[Persistent]
	public int $page = 1;   // must be public, non-static, typed
}
```

`loadState()` writes the URL value into the property and answers a type mismatch with a 404 – override it
for range checks; `saveState()` is the reverse direction. In links, `<a n:href="this page: $page + 1">`
changes the value and `page: null` resets it to the default (drops it from the URL).

**Persistent components** use the same attribute on the *presenter class*, listing component names;
their persistent parameters then survive across actions and presenters, subcomponents included:

```php
#[Persistent('calendar', 'poll')]
class DefaultPresenter extends Nette\Application\UI\Presenter
{
}
```

The annotation form `/** @persistent */` still works but triggers `E_USER_DEPRECATED` – always use the
attribute.

### AJAX and Snippets

```php
public function handleLike(int $id): void
{
	$this->service->like($id);
	if ($this->isAjax()) {
		$this->redrawControl('articles');   // NOT invalidateControl()
	} else {
		$this->redirect('this');
	}
}
```

- The method is **`redrawControl(?string $snippet = null, bool $redraw = true)`**. `invalidateControl()`
  does not exist any more – calling it dies with `Nette\MemberAccessException`. Pass `redraw: false` to
  cancel a pending invalidation. No argument invalidates the whole control.
- If **nothing** is invalidated, an AJAX request returns the whole page instead of snippets;
  `isControlInvalid()` is what the presenter checks, and it walks into child controls.
- **`redirect()` during AJAX does not send a 302.** It writes the URL into `payload.redirect` and sends
  the JSON payload; the browser side (Naja) performs the redirect. Therefore a handler that redirects
  ends the request – redraw *or* redirect, not both.
- Extra data for the client goes into the payload: `$this->payload->message = 'ok';`. The snippet's HTML
  id is `snippet-<uniqueId>-<name>` (`getSnippetId()`).

**A snippet redraw calls `render()` with no arguments** – Nette re-renders an invalidated child with a
plain `$child->render()`, so parameterized rendering is incompatible with snippets. Pass such values
through the factory, a setter or a persistent parameter instead.

```latte
{control productGrid}                  {* OK *}
{control productGrid $arg}             {* breaks on AJAX redraw *}
{control productGrid:paginator}        {* breaks on AJAX redraw *}
```

**Dynamic snippets** (a variable in the name) must sit inside a static `{snippet}` or `{snippetArea}`,
otherwise you get `E_USER_WARNING: Dynamic snippets are allowed only inside static snippet/snippetArea.`
Invalidate the *wrapper* – invalidating `item-5` alone redraws nothing, because that name only exists
once the surrounding loop runs.

```latte
<ul n:snippetArea="itemsContainer">
	{foreach $items as $id => $item}
		<li n:snippet="item-{$id}">{$item}</li>
	{/foreach}
</ul>
```

```php
$this->redrawControl('itemsContainer');
```

A redrawn area still *renders* every item and throws the rest away, so narrow the data in the handler
(`$this->template->items = [$one]`). The dynamic-snippet-free alternative is one `Control` per row plus
`Multiplier`, where only the affected instance renders.

### The Component Tree

```php
$this->getComponents();      // immediate children only, array, NO arguments
$this->getComponentTree();   // all descendants, depth-first, list
array_filter($this->getComponentTree(), fn($c) => $c instanceof Control);
```

- **`getComponents()` takes no arguments.** The old `$deep`/`$filterType` arguments left the signature in
  3.1 and throw `Nette\DeprecatedException` in 4.0, so `getComponents(true)` or
  `getComponents(recursive: true)` is always wrong. `getComponentTree()` has existed since 3.1 – it is
  not a new 4.0 API.
- `monitor($type, $attached, $detached)` reacts to (de)attachment; the overridable `attached()` /
  `detached()` methods were **removed in 4.0**, and `monitor()` with no handler throws
  `InvalidStateException`. In 4.0 attach callbacks fire top-down, detach callbacks bottom-up.
- `lookup($type)` returns the nearest ancestor of that type, `lookupPath($type)` the `-`-joined path from
  it – the basis of `getUniqueId()` and of the `do` parameter.
- A component **has no presenter in its constructor**: no links, no persistent parameter values there.
  Use `$onAnchor[]` (or `monitor(Presenter::class, ...)`) for setup that needs the presenter.
- `ComponentModel\Component` dropped the `SmartObject` trait in 4.0 (`UI\Component` still adds it).

### Multiplier

Creates a variable number of children on demand; the callback gets the child name and the multiplier.

```php
protected function createComponentLikeControl(): Multiplier
{
	return new Multiplier(fn(string $articleId) => new LikeControl($this->articles->get($articleId)));
}
```

```latte
{control "likeControl-$article->id"}
```

### Documentation

The full Nette documentation for this topic is bundled with the plugin. Read a page when you need details beyond this skill:

- [Components](../../docs/application/components.md) – factories, signals, persistent parameters
- [AJAX & Snippets](../../docs/application/ajax.md) – redrawing, payload, snippet areas
- [Dynamic Snippets](../../docs/best-practices/dynamic-snippets.md) – both approaches compared
- [Multiplier](../../docs/application/multiplier.md) – dynamic component creation
- [Creating Links](../../docs/application/creating-links.md) – signal syntax, links in components
- [POST Links](../../docs/best-practices/post-links.md) – signals that change state
- [Component Model](../../docs/component-model/index.md) – the component tree API, monitoring

Versions

The database has no other skills named nette-components.

Identical content appears in 1 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version 309096141066 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 80Angular Create Component Projectable Nodes v19
    Review Angular component creation with projectable nodes after Angular 19 when dynamic components depend on projected content, ng-content fallbacks, or component factory removal behavior. Use when createComponent or ViewContainerRef.createComponent is used with content projection.
  • 100nette-architecture
    Invoke before designing presenters, modules, or application structure in web application. Use when asking about directory structure (app/ folder organization), presenter organization (modules, Admin/Front/Api, BasePresenter), domain-driven placement (Core/ vs Model/), component…
  • 100frontend-development
    Provides frontend development guidelines for Nette. Use when working with Vite, SCSS, JavaScript/TypeScript, Nette Assets ({asset} tag, asset mapping), ESLint with @nette/eslint-plugin, Naja AJAX library, frontend entry points, npm packages in Nette context, Tailwind CSS with…
  • 100core-components
    Core component library and design system patterns. Use when building UI, using design tokens, or working with the component library.
  • 100barefootjs
    Build, inspect, and debug UI components using @barefootjs/cli. Use when: creating/editing/reviewing components, investigating signal dependencies, debugging reactive updates, scaffolding new components, or looking up component APIs.
  • 95glab-snippet
    Create GitLab project or personal code snippets with glab. Use when sharing code or text as a new snippet from files or stdin. For viewing, editing, or deleting existing snippets, use the GitLab UI or the snippets API through glab api. Triggers on snippet, gist, code snippet,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.