PHPackages                             imponeer/smarty-foreachq - 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. imponeer/smarty-foreachq

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

imponeer/smarty-foreachq
========================

Rewritten Smarty foreach variant that was invented for use in xoops, but nowadays is used in some other PHP based CMS'es

v2.0.2(5mo ago)020.5k↓33.3%MITPHPPHP ^8.3CI passing

Since Feb 2Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/imponeer/smarty-foreachq)[ Packagist](https://packagist.org/packages/imponeer/smarty-foreachq)[ RSS](/packages/imponeer-smarty-foreachq/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (14)Used By (0)

[![License](https://camo.githubusercontent.com/8d2d02aeaca2229545158f5bca55fbe9baa3084d9346b15755d746d2fd5e131e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d706f6e6565722f736d617274792d666f7265616368712e737667)](LICENSE) [![GitHub release](https://camo.githubusercontent.com/88abb0bfadd4504ff5c0fefdf27cf430714d96c1d75a0734cae6fc87f581b404/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f696d706f6e6565722f736d617274792d666f7265616368712e737667)](https://github.com/imponeer/smarty-foreachq/releases) [![PHP](https://camo.githubusercontent.com/b50d64925bbbdf1ab3838f2e4b997d1421cdfcb4f94d9f5fcc0d80e323f463d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696d706f6e6565722f736d617274792d666f7265616368712e737667)](http://php.net) [![Packagist](https://camo.githubusercontent.com/5a8a398253f7e53e7872e3edfedce752ec79a98c8f5e5caca672deb966f56f02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696d706f6e6565722f736d617274792d666f7265616368712e737667)](https://packagist.org/packages/imponeer/smarty-foreachq) [![Smarty version requirement](https://camo.githubusercontent.com/dc75d23e0a7213a8acbfcbcaa96d720b8a75a7049d5e5f790efd9b35410f591c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f696d706f6e6565722f736d617274792d666f7265616368712f736d61727479253246736d61727479)](https://smarty-php.github.io)

Smarty ForeachQ
===============

[](#smarty-foreachq)

> Backward compatibility foreach implementation for legacy XOOPS and ImpressCMS templates

Rewritten (due that original use [GPLv2+](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) license) [Smarty](https://smarty.net) foreach variant that was invented for use in [XOOPS](https://xoops.org), but nowadays used in some other PHP based CMS'es (like [ImpressCMS](https://impresscms.org)!).

See, [original version of this smarty plugin in Xoops](https://github.com/XOOPS/XoopsCore25/blob/v2.5.8/htdocs/class/smarty/xoops_plugins/compiler.foreachq.php) to see more accurate description why this plugin exists.

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

[](#installation)

To install and use this package, we recommend to use [Composer](https://getcomposer.org):

```
composer require imponeer/smarty-foreachq
```

Otherwise, you need to include manually files from `src/` directory.

Setup
-----

[](#setup)

### Basic Setup

[](#basic-setup)

To register the ForeachQ extension with Smarty, add the extension class to your Smarty instance:

```
// Create a Smarty instance
$smarty = new \Smarty\Smarty();

// Register the ForeachQ extension
$smarty->addExtension(new \Imponeer\Smarty\Extensions\ForeachQ\ForeachQExtension());
```

### Using with Symfony Container

[](#using-with-symfony-container)

To integrate with Symfony, you can leverage autowiring, which is the recommended approach for modern Symfony applications:

```
# config/services.yaml
services:
    # Enable autowiring and autoconfiguration
    _defaults:
        autowire: true
        autoconfigure: true

    # Register your application's services
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Tests,Kernel.php}'

    # Configure Smarty with the extension
    # The ForeachQExtension will be autowired automatically
    \Smarty\Smarty:
        calls:
            - [addExtension, ['@Imponeer\Smarty\Extensions\ForeachQ\ForeachQExtension']]
```

Then in your application code, you can simply retrieve the pre-configured Smarty instance:

```
// Get the Smarty instance with the ForeachQ extension already added
$smarty = $container->get(\Smarty\Smarty::class);
```

### Using with PHP-DI

[](#using-with-php-di)

With PHP-DI container, you can take advantage of autowiring for a very simple configuration:

```
use function DI\create;
use function DI\get;

return [
    // Configure Smarty with the extension
    \Smarty\Smarty::class => create()
        ->method('addExtension', get(\Imponeer\Smarty\Extensions\ForeachQ\ForeachQExtension::class))
];
```

Then in your application code, you can retrieve the Smarty instance:

```
// Get the configured Smarty instance
$smarty = $container->get(\Smarty\Smarty::class);
```

### Using with League Container

[](#using-with-league-container)

If you're using League Container, you can register the extension like this:

```
// Create the container
$container = new \League\Container\Container();

// Register Smarty with the ForeachQ extension
$container->add(\Smarty\Smarty::class, function() {
    $smarty = new \Smarty\Smarty();

    // Configure Smarty...

    // Create and add the ForeachQ extension
    $extension = new \Imponeer\Smarty\Extensions\ForeachQ\ForeachQExtension();
    $smarty->addExtension($extension);

    return $smarty;
});
```

Then in your application code, you can retrieve the Smarty instance:

```
// Get the configured Smarty instance
$smarty = $container->get(\Smarty\Smarty::class);
```

Usage
-----

[](#usage)

**Simple iteration:**

```
{foreachq from=$users item=user}
    User: {$user.name}
{/foreachq}
```

**With key and item:**

```
{foreachq from=$data key=index item=value}
    {$index}: {$value}
{/foreachq}
```

**Nested loops:**

```
{foreachq from=$categories item=category}
    {$category.name}
    {foreachq from=$category.items item=item}
        - {$item.title}
    {/foreachq}
{/foreachq}
```

Development
-----------

[](#development)

### Code Quality Tools

[](#code-quality-tools)

This project uses several tools to ensure code quality:

- **PHPUnit** - For unit testing

```
composer test
```

- **PHP CodeSniffer** - For coding standards (PSR-12)

```
composer phpcs    # Check code style
composer phpcbf   # Fix code style issues automatically
```

- **PHPStan** - For static analysis

```
composer phpstan
```

Documentation
-------------

[](#documentation)

API documentation is automatically generated and available in the project's wiki. For more detailed information about the classes and methods, please refer to the [project wiki](https://github.com/imponeer/smarty-foreachq/wiki).

Contributing
------------

[](#contributing)

Contributions are welcome! Here's how you can contribute:

1. Fork the repository
2. Create a feature branch: `git checkout -b feature-name`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin feature-name`
5. Submit a pull request

Please make sure your code follows the PSR-12 coding standard and include tests for any new features or bug fixes.

If you find a bug or have a feature request, please create an issue in the [issue tracker](https://github.com/imponeer/smarty-foreachq/issues).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 56.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 ~160 days

Recently: every ~244 days

Total

12

Last Release

158d ago

Major Versions

v1.1.7 → v2.0.02025-07-22

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

v2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dba53e399a507d1f60626164c8b1e340a5cc0dc4f0637f4c6aaff8fc239fdaee?d=identicon)[fiammybe](/maintainers/fiammybe)

![](https://www.gravatar.com/avatar/7255f306e0ca27292c50cdd9644c1c04e0d7b0f54bf35e0cdd79dc55c83b4923?d=identicon)[MekDrop](/maintainers/MekDrop)

![](https://www.gravatar.com/avatar/79009323fafcd4974bb1713b12eea0a610f01c4fb21cc5e85d446c4cb66453d4?d=identicon)[skenow](/maintainers/skenow)

---

Top Contributors

[![MekDrop](https://avatars.githubusercontent.com/u/342641?v=4)](https://github.com/MekDrop "MekDrop (37 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (24 commits)")[![Codex](https://avatars.githubusercontent.com/in/2248422?v=4)](https://github.com/Codex "Codex (2 commits)")[![fiammybe](https://avatars.githubusercontent.com/u/3736946?v=4)](https://github.com/fiammybe "fiammybe (2 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")

---

Tags

foreachhacktoberfestsmartysmarty-pluginssmartyforeachxoopssmarty-plugins

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/imponeer-smarty-foreachq/health.svg)

```
[![Health](https://phpackages.com/badges/imponeer-smarty-foreachq/health.svg)](https://phpackages.com/packages/imponeer-smarty-foreachq)
```

###  Alternatives

[ytake/laravel-smarty

Smarty template engine for Laravel and Lumen

87401.6k](/packages/ytake-laravel-smarty)[noiselabs/smarty-bundle

This Symfony bundle provides integration for the Smarty3 template engine.

53194.4k1](/packages/noiselabs-smarty-bundle)[latrell/smarty

This package lets you run Smarty3 on Laravel5 elegantly.

137.0k](/packages/latrell-smarty)

PHPackages © 2026

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