PHPackages                             nepada/form-renderer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. nepada/form-renderer

ActiveLibrary[Templating &amp; Views](/categories/templating)

nepada/form-renderer
====================

Latte template based form renderer for Nette forms with full support for Bootstrap 3, 4 &amp; 5.

v1.12.3(5mo ago)11251.0k↓44.3%2[3 PRs](https://github.com/nepada/form-renderer/pulls)BSD-3-ClauseHTMLPHP &gt;=8.1.0 &lt;8.6CI failing

Since Aug 13Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/nepada/form-renderer)[ Packagist](https://packagist.org/packages/nepada/form-renderer)[ RSS](/packages/nepada-form-renderer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (39)Used By (0)

Form Renderer
=============

[](#form-renderer)

[![Build Status](https://github.com/nepada/form-renderer/workflows/CI/badge.svg)](https://github.com/nepada/form-renderer/actions?query=workflow%3ACI+branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/0ab5f1c98248238bb009c8249f6799b05fd90907e7c294a2d7bce6a7b9bbce0f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e65706164612f666f726d2d72656e64657265722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/nepada/form-renderer?branch=master)[![Downloads this Month](https://camo.githubusercontent.com/e2b2029aef1fd3abf8ca4722e4e9b1bbd154252e8e6b798b2f4b076bdeb9c089/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e65706164612f666f726d2d72656e64657265722e737667)](https://packagist.org/packages/nepada/form-renderer)[![Latest stable](https://camo.githubusercontent.com/3a4cff613ed3a86fd0519f4ca035627b5f224e1a5afbfb6a0ab67dd1e9b75875/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65706164612f666f726d2d72656e64657265722e737667)](https://packagist.org/packages/nepada/form-renderer)

Installation
------------

[](#installation)

Via Composer:

```
$ composer require nepada/form-renderer
```

Register the extension in `config.neon`:

```
extensions:
    formRenderer: Nepada\Bridges\FormRendererDI\FormRendererExtension
```

Usage
-----

[](#usage)

Nette gives you two options how to render a form:

1. Render the whole form manually in Latte template using form macros. This way you have complete control over the rendering, but writing all the templates quickly gets repetitive.
2. Render it using a form renderer, e.g. `DefaultFormRenderer` from `nette/forms`. `DefaultFormRenderer` is very customizable, but it's hard to setup special rendering rules for only some controls of a form, or add support for rendering of new form control types.

`nepada/form-renderer` is built on top of Latte templates and their powerful blocks, thus combining strengths of manual rendering with DRY principle of form renderers.

### TemplateRenderer

[](#templaterenderer)

You can use `TemplateRendererFactory` service to create the renderer with preconfigured [default template](src/FormRenderer/templates/default.latte). It renders a form more or less the same way as `DefaultFormRenderer`.

#### Customizing rendering

[](#customizing-rendering)

You can customize rendering by importing blocks from a template file - blocks imported later override the previously imported ones of the same name. You can also pass custom variables to the template.

```
/** @var Nepada\FormRenderer\TemplateRendererFactory $factory */
$renderer = $factory->create();
$renderer->importTemplate(__DIR__ . '/custom-form-rendering-blocks.latte');
$renderer->getTemlate()->foo = 'bar';
$form->setRenderer($renderer);
```

**Tips:**

- You can define special rendering for a specific control of a form in `#control-name-*` block (e.g. `#control-name-container-subcontainer-foocontrol`).
- If you need special rendering for both a control and its label, define it in `#pair-name-*` block.
- Rendering of different control types (based on the value of `$control->getOption('type')`) is controlled by blocks `#control-type-*` and `#pair-type-*`. The default template actually uses this for buttons (rendering of consecutive buttons in one row).
- You can also specify template files to be imported in your `config.neon`: ```
    formRenderer:
        default:
            imports:
                - %appDir%/templates/@form-extras1.latte
                - %appDir%/templates/@form-extras2.latte
    ```

For a complete overview of supported blocks and better understanding how the renderer works, please read the code of the [template](src/FormRenderer/templates/default.latte).

#### Creating custom TemplateRenderer setup from scratch

[](#creating-custom-templaterenderer-setup-from-scratch)

You don't need to use the default template, you can create one from scratch with blocks tailored to your needs. You can define factory for your custom setup like this:

```
services:
    customRenderer:
        implement: Nepada\FormRenderer\TemplateRendererFactory
        setup:
          - importTemplate('%appDir%/templates/@form.latte')
          - importTemplate('%appDir%/templates/@form-extras.latte')
```

Just make sure that one of your template files defines block named `#form` - this is used as a starting point for the rendering.

#### Filter `safeTranslate` in templates

[](#filter-safetranslate-in-templates)

For translations the templates may use custom `safeTranslate` filter. The key differences from standard `translate` filter are:

1. It avoids translating instances of `Nette\Utils\IHtmlString` and `Latte\Runtime\IHtmlString`.
2. It uses a translator from the form instance that is being rendered.
3. If the form has no translator set, than it simply returns the passed string untranslated.

#### Improved version of `n:class` macro

[](#improved-version-of-nclass-macro)

In all form templates there is also available an improved version of `n:class` macro that supports merging of classes from `Nette\Utils\Html` instances. You can do stuff like `` and don't need to worry if the class attribute is really represented as a string or array, it all just works.

### Bootstrap5Renderer

[](#bootstrap5renderer)

Form renderer compatible with Bootstrap 5, it internally uses `TemplateRenderer` with [custom template](src/FormRenderer/templates/boostrap5.latte).

The template supports three rendering modes:

```
/** @var Nepada\FormRenderer\Bootstrap5RendererFactory $factory */
$renderer = $factory->create();
$renderer->setBasicMode(); // Basic form
$renderer->setInlineMode(); // Inline form
$renderer->setHorizontalMode(4, 8); // Horizontal form (you can optionally set the size of label and control columns)
```

Use `$renderer->setRenderValidState(true)` to enable/disable rendering of "valid" form control state for filled inputs after form submission.

In inline mode the error messages are always rendered as tooltips. In the other modes you can switch between standard and tooltip rendering by calling `$renderer->setUseErrorTooltips(true)`.

You can enable [floating labels](https://getbootstrap.com/docs/5.3/forms/floating-labels/) by `$renderer->setUseFloatingLabels(true)` (ignored in horizontal mode only). By default, all controls of `text`, `datetime`, `textarea` and `select` type are rendered with floating label, but you can manually override this on a specific control by setting `$input->setOption('floatingLabel', false)`.

To render a checkbox as a switch, you need to set type option: `$checkboxInput->setOption('type', 'switch')`.

To render radio or checkbox as a [toggle button](https://getbootstrap.com/docs/5.3/forms/checks-radios/#toggle-buttons), add `btn` class (and any desired button styling class) to label prototype: `$radio->getItemLabelPrototype()->addClass('btn btn-outline-primary')`.

`Bootstrap5Renderer` makes a couple of adjustments to the form before it is passed over to `TemplateRenderer`:

1. It adds `btn btn-primary` classes to the control prototype of first `SubmitButton` in the form, unless there already is such a control in the form.
2. It adds `btn btn-secondary` classes to the control prototype of every `Button` control, unless it already has `btn` class set.
3. Changes `type` option on all `Checkbox`, `CheckboxList`, `RadioList` controls setup to be rendered as toggle buttons from `checkbox`/`radio` to `togglebutton`/`togglebuttonlist`.
4. Changes `type` option on all `CheckboxList` controls from `checkbox` to `checkboxlist`.
5. When floating labels are enabled, it sets boolean `floatingLabel` option (unless already set) on all controls to indicate whether the floating label should be rendered.

You can change the default renderer configuration from your `config.neon`:

```
formRenderer:
  bootstrap5:
    mode: horizontal
    renderValidState: true
    useErrorTooltips: true
    imports:
      - %appDir%/templates/@form-extras.latte
```

### Bootstrap4Renderer

[](#bootstrap4renderer)

Form renderer compatible with Bootstrap 4, it internally uses `TemplateRenderer` with [custom template](src/FormRenderer/templates/boostrap4.latte).

The template supports three rendering modes:

```
/** @var Nepada\FormRenderer\Bootstrap4RendererFactory $factory */
$renderer = $factory->create();
$renderer->setBasicMode(); // Basic form
$renderer->setInlineMode(); // Inline form
$renderer->setHorizontalMode(4, 8); // Horizontal form (you can optionally set the size of label and control columns)
```

Use `$renderer->setRenderValidState(true)` to enable/disable rendering of "valid" form control state for filled inputs after form submission.

In inline mode the error messages are always rendered as tooltips. In the other modes you can switch between standard and tooltip rendering by calling `$renderer->setUseErrorTooltips(true)`.

You can enable the use of [custom form controls](https://getbootstrap.com/docs/4.4/components/forms/#custom-forms) by `$renderer->setUseCustomControls(true)`.

To render a checkbox as a switch, you need to set type option: `$checkboxInput->setOption('type', 'switch')`.

`Bootstrap4Renderer` makes a couple of adjustments to the form before it is passed over to `TemplateRenderer`:

1. It adds `btn btn-primary` classes to the control prototype of first `SubmitButton` in the form, unless there already is such a control in the form.
2. It adds `btn btn-secondary` classes to the control prototype of every `Button` control, unless it already has `btn` class set.
3. Changes `type` option on all `CheckboxList` controls from `checkbox` to `checkboxlist`.

You can change the default renderer configuration from your `config.neon`:

```
formRenderer:
    bootstrap4:
        mode: horizontal
        renderValidState: true
        useErrorTooltips: true
        useCustomControls: true
        imports:
            - %appDir%/templates/@form-extras.latte
```

### Bootstrap3Renderer

[](#bootstrap3renderer)

Form renderer compatible with Bootstrap 3, it internally uses `TemplateRenderer` with [custom template](src/FormRenderer/templates/boostrap3.latte).

The template supports three rendering modes:

```
/** @var Nepada\FormRenderer\Bootstrap3RendererFactory $factory */
$renderer = $factory->create();
$renderer->setBasicMode(); // Basic form
$renderer->setInlineMode(); // Inline form
$renderer->setHorizontalMode(4, 8); // Horizontal form (you can optionally set the size of label and control columns)
```

Use `$renderer->setRenderValidState(true)` to enable/disable rendering of "valid" form control state for filled inputs after form submission.

`Bootstrap3Renderer` makes a couple of adjustments to the form before it is passed over to `TemplateRenderer`:

1. It adds `btn btn-primary` classes to the control prototype of first `SubmitButton` in the form, unless there already is such a control in the form.
2. It adds `btn btn-default` classes to the control prototype of every `Button` control, unless it already has `btn` class set.
3. Changes `type` option on all `CheckboxList` controls from `checkbox` to `checkboxlist`.

You can change the default renderer configuration from your `config.neon`:

```
formRenderer:
    bootstrap3:
        mode: horizontal
        renderValidState: true
        imports:
            - %appDir%/templates/@form-extras.latte
```

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance81

Actively maintained with recent releases

Popularity40

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~91 days

Recently: every ~171 days

Total

34

Last Release

176d ago

PHP version history (8 changes)v1.0.0PHP &gt;=7.1.0

v1.3.0PHP &gt;=7.2.0

v1.4.0PHP &gt;=7.4.0

v1.9.0PHP &gt;=7.4.0 &lt;8.2

v1.10.1PHP &gt;=7.4.0 &lt;8.3

v1.11.0PHP &gt;=8.1.0 &lt;8.4

v1.12.1PHP &gt;=8.1.0 &lt;8.5

v1.12.3PHP &gt;=8.1.0 &lt;8.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b4780fe328102c4572737db639653c29d3081d1d3e051467f00d7f09a776399?d=identicon)[xificurk](/maintainers/xificurk)

---

Top Contributors

[![xificurk](https://avatars.githubusercontent.com/u/117465?v=4)](https://github.com/xificurk "xificurk (228 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (169 commits)")[![Gappa](https://avatars.githubusercontent.com/u/749981?v=4)](https://github.com/Gappa "Gappa (1 commits)")[![martenb](https://avatars.githubusercontent.com/u/13311472?v=4)](https://github.com/martenb "martenb (1 commits)")

---

Tags

netterendererbootstrapFormslatte

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nepada-form-renderer/health.svg)

```
[![Health](https://phpackages.com/badges/nepada-form-renderer/health.svg)](https://phpackages.com/packages/nepada-form-renderer)
```

###  Alternatives

[contributte/forms-bootstrap

Nette extension for Bootstrap forms

211.1M4](/packages/contributte-forms-bootstrap)[tomaj/nette-bootstrap-form

Nette bootstrap form renderer

28440.4k6](/packages/tomaj-nette-bootstrap-form)[nextras/forms-rendering

Rendering helpers for Nette Framework Forms.

1698.4k2](/packages/nextras-forms-rendering)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
