PHPackages                             tomaj/nette-auto-variable-template - 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. tomaj/nette-auto-variable-template

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

tomaj/nette-auto-variable-template
==================================

Auto variable template factory

3.0.0(5mo ago)2134.9k↑19%2LGPL-2.0-or-laterPHPPHP &gt;= 8.1.0

Since Aug 28Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/tomaj/nette-auto-variable-template)[ Packagist](https://packagist.org/packages/tomaj/nette-auto-variable-template)[ RSS](/packages/tomaj-nette-auto-variable-template/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

Nette Auto Variable Template Factory
====================================

[](#nette-auto-variable-template-factory)

[![Latest Stable Version](https://camo.githubusercontent.com/dae5499d7871259ee394ce5b0b98621a459757b0c3f7f40b4b15f01ea5fbe4f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6d616a2f6e657474652d6175746f2d7661726961626c652d74656d706c6174652e737667)](https://packagist.org/packages/tomaj/nette-auto-variable-template)[![License](https://camo.githubusercontent.com/6a7c2052ecfc787ef4b6a71d290aa5a6e7682351418ea3c594b1f0e3878a35ec/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4c47504c2d2d322e302d2d6f722d2d6c617465722d626c75652e737667)](LICENSE)

A lightweight Nette Framework library that automatically injects variables into all Latte templates, including component templates. This is useful when you need certain variables (such as application settings, user preferences, or global configuration) to be available across all templates without manually passing them from each presenter or component.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Nette Application ^3.2
- Nette Utils ^4.0

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

[](#installation)

Install the package via Composer:

```
composer require tomaj/nette-auto-variable-template
```

Usage
-----

[](#usage)

### Basic Configuration

[](#basic-configuration)

Register the custom template factory in your `config.neon` file. The library wraps the default Latte template factory and automatically assigns your registered variables to every template:

```
services:
    latte.templateFactory:
        autowired: no

    templateFactory:
        factory: Tomaj\Latte\AutoVariableTemplateFactory(@latte.templateFactory)
        setup:
            - registerVariable('appName', 'My Application')
            - registerVariable('settings', @App\Model\SettingsService)
```

### Using Variables in Templates

[](#using-variables-in-templates)

Once configured, the registered variables are automatically available in all your Latte templates:

```
{$appName}
Version: {$settings->getVersion()}
```

### Registering Services

[](#registering-services)

You can register any value as a template variable, including services from the DI container:

```
services:
    templateFactory:
        factory: Tomaj\Latte\AutoVariableTemplateFactory(@latte.templateFactory)
        setup:
            - registerVariable('user', @security.user)
            - registerVariable('translator', @translator)
            - registerVariable('config', @App\Model\ConfigService)
```

### onCreate Event

[](#oncreate-event)

The factory also provides an `onCreate` event that fires whenever a template is created, allowing you to perform additional template customization:

```
$templateFactory->onCreate[] = function (Template $template) {
    // Custom template initialization
};
```

How It Works
------------

[](#how-it-works)

The `AutoVariableTemplateFactory` implements `Nette\Application\UI\TemplateFactory` and acts as a decorator around the default template factory. When a template is created:

1. The inner (original) template factory creates the template
2. All registered variables are automatically assigned to the template
3. The `onCreate` event is triggered
4. The template is returned ready to use

This approach ensures that variables are available in presenter templates, component templates, and any other templates created through the factory.

License
-------

[](#license)

This library is licensed under the LGPL-2.0-or-later license. See the [LICENSE](LICENSE) file for details.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance71

Regular maintenance activity

Popularity35

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 61.9% 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 ~938 days

Total

5

Last Release

164d ago

Major Versions

1.0 → 2.0.02019-04-18

2.2.0 → 3.0.02025-12-05

PHP version history (3 changes)1.0PHP &gt;= 5.4.0

2.0.0PHP &gt;= 7.1.0

3.0.0PHP &gt;= 8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/875f8397233f01d81479a45bf6a64ca995f04d8ee9e72118f2ffcf129c502f12?d=identicon)[tomaj](/maintainers/tomaj)

---

Top Contributors

[![tomaj](https://avatars.githubusercontent.com/u/446736?v=4)](https://github.com/tomaj "tomaj (13 commits)")[![ricco24](https://avatars.githubusercontent.com/u/1409647?v=4)](https://github.com/ricco24 "ricco24 (6 commits)")[![lulco](https://avatars.githubusercontent.com/u/9377319?v=4)](https://github.com/lulco "lulco (2 commits)")

---

Tags

nettelatteglobalvariable

### Embed Badge

![Health badge](/badges/tomaj-nette-auto-variable-template/health.svg)

```
[![Health](https://phpackages.com/badges/tomaj-nette-auto-variable-template/health.svg)](https://phpackages.com/packages/tomaj-nette-auto-variable-template)
```

###  Alternatives

[nepada/form-renderer

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

11251.0k](/packages/nepada-form-renderer)[contributte/forms-bootstrap

Nette extension for Bootstrap forms

211.1M4](/packages/contributte-forms-bootstrap)[contributte/latte

Extra contrib to nette/latte

111.5M2](/packages/contributte-latte)

PHPackages © 2026

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