PHPackages                             lovecoding/twig-asset - 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. lovecoding/twig-asset

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

lovecoding/twig-asset
=====================

A simple twig asset extension for Slim 3.x

v1.1.0(7y ago)11.2k[1 issues](https://github.com/thangl3/simple-twig-asset/issues)MITPHPPHP ^7.0

Since Nov 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/thangl3/simple-twig-asset)[ Packagist](https://packagist.org/packages/lovecoding/twig-asset)[ RSS](/packages/lovecoding-twig-asset/feed)WikiDiscussions master Synced 3w ago

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

Simple Twig Asset
=================

[](#simple-twig-asset)

This is a simple twig asset extension for Slim 3.x helper manage your resource in the Twig templating component. When you want to change the public resource, with the traditional way, you must change URL resource one by one for each resource in each template `.twig`. With TwigAsset, you don't worry about that, with simple way, you can change all of the resources to new URL. Besides, it's helping you against browser cached resource with a set suffix at the end of resource URL, all of that is automated. And so more it can do.

Install
-------

[](#install)

Via [Composer](https://getcomposer.org/)

```
$ composer require lovecoding/twig-asset
```

Requires Slim Framework 3.x and PHP 7.0.0 or newer.

Usage
-----

[](#usage)

### Setup

[](#setup)

- In php

```
// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Twig View helper
$container['view'] = function ($c) {
    $view = new \Slim\Views\Twig('path/to/templates');

    // Instantiate and add Slim specific extension
    $router = $c->get('router');
    $uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER));
    $view->addExtension(new \Slim\Views\TwigExtension($router, $uri));

    $assetManager = new LoveCoding\TwigAsset\TwigAssetManagement([
        'verion' => '1'
    ]);
    $assetManager->addPath('css', '/css');
    $assetManager->addPath('img', '/images');
    $assetManager->addPath('js', '/js');
    $view->addExtension($assetManager->getAssetExtension());

    return $view;
};

// Define named route
$app->get('/home', function ($request, $response, $args) {
    return $this->view->render($response, 'home.html');
});

// Run app
$app->run();
```

- In `home.html`

In this version `TwigAsset` only provide one function to your Twig templates:

```
- `asset(path, namespace)` - returns the real URL resource from your `path`.
    - path - your static `path`.
    - namespace - group the resource to only one name, the url will be shorted.

```

```
>

```

### Example settings

[](#example-settings)

- Example 1

```
$settings = [
    'version' => '1', // version will be setting in the end of asset url `css.css?(version_format here)`
    'version_format' => '%s?v=%s',
];

// in the html if you call asset('/image.png')
// the result: /v1/image.png?v=1
```

- Example 2

```
$settings = [
    'version' => 'v1',
    'version_format' => '%2$s/%1$s',
];

// in the html if you call asset('/image.png')
// the result: /v1/image.png
```

- Example 3

```
// rev-manifest.json
{
    "css/app.css": "build/css/app.b916426ea1d10021f3f17ce8031f93c2.css",
    "js/app.js": "build/js/app.13630905267b809161e71d0f8a0c017b.js",
    "...": "..."
}
```

```
$settings = [
    'json_manifest' => __DIR__.'/rev-manifest.json'
];

// in the html if you call asset('css/app.css')
// the result: css/app.b916426ea1d10021f3f17ce8031f93c2.css
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~22 days

Total

2

Last Release

2757d ago

### Community

Maintainers

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

---

Top Contributors

[![thang-d](https://avatars.githubusercontent.com/u/15165794?v=4)](https://github.com/thang-d "thang-d (7 commits)")

---

Tags

assets-managementslim-frameworktemplate-enginetwigtwig-assettwig-asset-slimtwig-extension

### Embed Badge

![Health badge](/badges/lovecoding-twig-asset/health.svg)

```
[![Health](https://phpackages.com/badges/lovecoding-twig-asset/health.svg)](https://phpackages.com/packages/lovecoding-twig-asset)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M737](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.8k](/packages/contao-core-bundle)

PHPackages © 2026

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