PHPackages                             cf-git/twig-once - 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. cf-git/twig-once

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

cf-git/twig-once
================

Twig template tag {% once \[name\] %}{% endonce %}

1.0.7(2y ago)06BSD-3-ClausePHPPHP &gt;7.2

Since Dec 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/cf-git/twig-once)[ Packagist](https://packagist.org/packages/cf-git/twig-once)[ RSS](/packages/cf-git-twig-once/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

twig-once
=========

[](#twig-once)

MicroExtension for Twig template library. Can be used when need restrict once some part of code.

**`twig/twig` library is required**.

How to use.
-----------

[](#how-to-use)

1.Require this extension with your composer

```
composer require cf-git/twig-once
```

2.include autoload file in your php project (if it not included);

```
include_once('vendor/autoload.php');
```

3.add token parser to Twig\\Environment

```
$twig = new \Twig\Environment($loader, $config);
$twig->addExtension(new \CFGit\TwigEngine\Extensions\Once\OnceExtension())
```

or like this

```
$twig = new \Twig\Environment($loader, $config);
$twig->addTokenParser(new \CFGit\TwigEngine\Extensions\Once\OnceTokenParser());
```

4.Then use twig documentation!

And use it.

### If you do right. You gets some like this.

[](#if-you-do-right-you-gets-some-like-this)

```
{{-- Main content --}}

{% for i in range(0, 5) %}
    {{ i }}
    {% once hello %}
    console.log("[{{ i }}]Hello world!")
    {% endonce %}
{% endfor %}
```

outputs

```
0
console.log("[0] Hello world!")
1
2
3
4
5
```

### Same with included files

[](#same-with-included-files)

```
{{-- Main content --}}

{% for i in range(0,5) %}
  {% include "x.twig" with({(i): i}) %}
{% endfor %}
```

```
{{-- x.twig content --}}

{% once %}

{% endonce %}
```

outputs

```

```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

931d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4868249b74dd2118b8fe42d7b28930232cf07e2d30e7a36b702db1665585ab00?d=identicon)[cf-git](/maintainers/cf-git)

---

Top Contributors

[![cf-git](https://avatars.githubusercontent.com/u/18499356?v=4)](https://github.com/cf-git "cf-git (8 commits)")

### Embed Badge

![Health badge](/badges/cf-git-twig-once/health.svg)

```
[![Health](https://phpackages.com/badges/cf-git-twig-once/health.svg)](https://phpackages.com/packages/cf-git-twig-once)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)

PHPackages © 2026

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