PHPackages                             cscfa/twig\_ui\_bundle - 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. cscfa/twig\_ui\_bundle

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

cscfa/twig\_ui\_bundle
======================

The TwigUIBundle is a symfony2 bundle that provide process to use modules

1.0.1(10y ago)023[2 issues](https://github.com/cscfa/TwigUIBundle/issues)MITPHPPHP &gt;=5.3.9

Since Mar 23Pushed 10y ago1 watchersCompare

[ Source](https://github.com/cscfa/TwigUIBundle)[ Packagist](https://packagist.org/packages/cscfa/twig_ui_bundle)[ RSS](/packages/cscfa-twig-ui-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

TwigUIBundle
============

[](#twiguibundle)

### Version: 1.0.0

[](#version-100)

The TwigUIBundle is a symfony2 bundle that provide process to use modules.

\#####Installation

Register the bundle into app/appKernel.php

```
// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            [...]
            new Cscfa\Bundle\TwigUIBundle\CscfaTwigUIBundle(),
        );

        [...]
    }
}

```

### Create a module

[](#create-a-module)

The TwigUIBundle allow to create modules to process an twig rendering as hierarchic modules.

Two modules types exists :

- The TopLevelModule
- The StepModule

The TopLevelModules represents the modules that are directly injected into the module set of a controller. To create a TopLevelModule, you must create a class that extends AbstractTopLevelModule. This abstract class implements the base methods and process to inject the template and arguments to render into the module environment.

The StepModule represents the childs modules of a TopLevelModule. It work as the TopLevelModule but you must extends the AbstractStepModules.

```
use Cscfa\Bundle\TwigUIBundle\Modules\AbstractTopLevelModule;
// or
use Cscfa\Bundle\TwigUIBundle\Modules\AbstractStepModule;
```

You must define the 'getName()' and 'render(EnvironmentContainer $environment)' methods. The 'getName' method must return an unique as possible string to be used as template's calling definition alias. The 'render' method is the method where you can write you'r php logic.

The 'render' method is allowed to return 'null' or an instance of 'TwigRequest'. Returning null indicate that the module not create any twig view.

The 'EnvironmentContainer' instance passed to 'render' method allow to access to the informations given by the controller.

```
// Get a registed object. By default, only the User instance is given by the controller
$environment->getObjectsContainer()->getObject($alias);

// Get the current controller name
$environment->getControllerInfo()->getControllerName();

// Get the current controller method
$environment->getControllerInfo()->getMethodName();
```

### Create a twig request

[](#create-a-twig-request)

The 'TwigRequest' class allow to store informations to render a twig template behind the usage of EnvironmentContainer.

A 'TwigRequest' instance store a template name and the calling arguments.

```
$twigRequest = new TwigRequest();
$twigRequest->setTwigPath("AcmeBundle:Default:index.html.twig");
$twigRequest->setArguments(array(
    "fooArgument" => "foo",
    "barArgument" => "bar",
));
$twigRequest->remArgument("barArgument");
$twigRequest->hasArgument("fooArgument");
```

The 'TwigRequest' class allow to store childs but this is currently managed by the hierarchization of the modules.

```
// Note the constructor allow to pass the template path and the arguments.
$twigRequest->addChildRequest(
    new TwigRequest(
        "AcmeBundle:Default:index.html.twig",
        array("fooArgument" => "foo")
    ),
    "ChildAliasName"
);
```

### Register you'r module

[](#register-your-module)

The modules are registered as tagged services.

The tags that needs to be defined are:

- name : 'cs.module'
- cs.module.parent : the name of the parent module
- cs.module.hydrate : the method to call to register into the parent

The value of the 'name' tag can be customize into the TwigUIBundle configuration.

The tag that target the parent can be customize into the TwigUIBundle configuration.

The tag that define the method to call can be customize into the TwigUIBundle configuration.

Here an exemple of TwigUIBundle configuration :

```
# /app/config.yml
cscfa_twig_ui:
    modules:
        - tag_name: cs.module
        - parent_tag: cs.module.parent
        - method_tag: cs.module.hydrate
```

The services are stored by default into an instance of ModuleSet that process the contained modules in order of they priority. The priority can be define into the service definition. The priority is stored as float value.

Here an example of module definition present into the unit tests:

```
cscfa_twig_ui.test.main:
    class: Cscfa\Bundle\TwigUIBundle\Modules\ModuleSet

cscfa_twig_ui.test.firstTop:
    class: Cscfa\Bundle\TwigUIBundle\FunctionalTest\Object\FirstTopLevel
    calls:
        - [ setPriority, [ 10 ]]
    tags:
        - { name: cs.module, cs.module.parent: cscfa_twig_ui.test.main, cs.module.hydrate: addModule }
```

### Use modules into you'r controller

[](#use-modules-into-your-controller)

In the last example, you can see that the first service is an instance of ModuleSet. It's the service that the controller will call to process the modules, so you must create a service that instanciate ModuleSet.

To create a controller that process modules, you must extends the 'ModulableController'. This class provide access to the 'processModule' method.

In the following example, the controller return directly the twig result of the the first argument template. The second argument define the current method and the third indicate the main ResultSet service that contain the modules.

```
class AcmeController extends ModulableController
{
    public function processAction()
    {
        return $this->processModule(
            'CscfaTwigUIBundle:test:controllerResult.html.twig',
            __METHOD__,
            'cscfa_twig_ui.test.main'
        );
    }
}
```

The 'processModule' method take a fourth optional 'EnvironmentOptionBuilder' argument. It allow to give optional parameters to the Environment.

The followed exemple make the current accessible from the modules :

```
class AcmeController extends ModulableController
{
    public function processAction(Request $request)
    {
        $builder = new EnvironmentOptionBuilder();
        $builder->addOption(
            $builder::OBJECT_CONTAINER_OBJECT,
            array($request, "request")
        );

        return $this->processModule(
            'CscfaTwigUIBundle:test:controllerResult.html.twig',
            __METHOD__,
            'cscfa_twig_ui.test.main',
            $builder
        );
    }
}

class module extends AbstractTopLevelModule
{
    public function render(EnvironmentContainer $environment)
    {
        $environment->getObjectsContainer()
            ->getObject("request");
    }
}
```

The 'EnvironmentOptionBuilder' allow to register options withe the following types :

typeargument formatOBJECT\_CONTAINER\_OBJECTarray($object, "alias")CONTROLLER\_INFO\_CONTROLLER"controller name"CONTROLLER\_INFO\_METHOD"controller method"TWIG\_REQUEST\_TWIG\_REQUESTarray($twigRequest, "alias")### Create a module template

[](#create-a-module-template)

The template that display the result of the controller must call the 'twigUIEnvironment' function. The module environment is directly passed as 'environment' variable.

```
>

Insert title here

    {{ twigUIEnvironment(environment) }}

```

The step templates receive the arguments as defined into the TwigRequest and the additionals 'moduleName' and 'moduleChilds' variable. They must call the 'twigUIModule' function to render the childs modules.

```

    {{ argument }}

    {{ twigUIModule(moduleChilds) }}

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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

3751d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12436206?v=4)[cscfa](/maintainers/cscfa)[@cscfa](https://github.com/cscfa)

---

Top Contributors

[![matthieu88160](https://avatars.githubusercontent.com/u/11874266?v=4)](https://github.com/matthieu88160 "matthieu88160 (3 commits)")

---

Tags

modulecscfa

### Embed Badge

![Health badge](/badges/cscfa-twig-ui-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/cscfa-twig-ui-bundle/health.svg)](https://phpackages.com/packages/cscfa-twig-ui-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M378](/packages/easycorp-easyadmin-bundle)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

566.8M117](/packages/symfony-ux-icons)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1175.2k](/packages/rcsofttech-audit-trail-bundle)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

1682.8k1](/packages/symfony-ux-toolkit)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)

PHPackages © 2026

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