PHPackages                             odan/plates-asset-cache - 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. [Caching](/categories/caching)
4. /
5. odan/plates-asset-cache

AbandonedArchivedLibrary[Caching](/categories/caching)

odan/plates-asset-cache
=======================

Caching and compression for Plates template assets (JavaScript and CSS).

2.1.0(5y ago)42.4k2[3 PRs](https://github.com/odan/plates-asset-cache/pulls)MITPHPPHP ^7.3 || ^8.0

Since Sep 6Pushed 5y agoCompare

[ Source](https://github.com/odan/plates-asset-cache)[ Packagist](https://packagist.org/packages/odan/plates-asset-cache)[ Docs](https://github.com/odan/plates-asset-cache)[ RSS](/packages/odan-plates-asset-cache/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (10)Versions (24)Used By (0)

Plates Assets Cache Extension
=============================

[](#plates-assets-cache-extension)

Caching and compression for Plates template assets (JavaScript and CSS).

[![Latest Version on Packagist](https://camo.githubusercontent.com/16a74e6f922cb38e97cb11fc6cdb2b40e63ace1903bd150607ed261567b42435/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6f64616e2f706c617465732d61737365742d63616368652e737667)](https://github.com/odan/plates-asset-cache/releases)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://github.com/odan/plates-asset-cache/workflows/build/badge.svg)](https://github.com/odan/plates-asset-cache/actions)[![Code Coverage](https://camo.githubusercontent.com/6b765165fc06b61cdccdc0f1bd5384487b1e3683e085fbf28404a93a5f61f5d5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f64616e2f706c617465732d61737365742d63616368652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/odan/plates-asset-cache/code-structure)[![Quality Score](https://camo.githubusercontent.com/6abe322f0b3c0a2e5513200fc48f073c0ba463d91754198cc779e9925495cd78/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f64616e2f706c617465732d61737365742d63616368652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/odan/plates-asset-cache/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/3f5f1403234cec8d066a36c7820e9d99d9ef48059202d54a6a3aad4b2753ec3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f64616e2f706c617465732d61737365742d63616368652e737667)](https://packagist.org/packages/odan/plates-asset-cache/stats)

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

[](#installation)

```
composer require odan/plates-asset-cache

```

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

[](#requirements)

- PHP 7.3+ or 8.0+

Configuration
-------------

[](#configuration)

```
use League\Plates\Engine;
use Odan\PlatesAsset\AssetEngine;
use Odan\PlatesAsset\PlatesAssetExtension;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$engine = new Engine('/path/with/html/templates');

$options = [
    // Public assets cache directory
    'path' => '/var/www/example.com/htdocs/public/assets/cache',

    // Public cache directory permissions (octal)
    // You need to prefix mode with a zero (0)
    // Use -1 to disable chmod
    'path_chmod' => 0750,

    // The public url base path
    'url_base_path' => 'assets/cache/',

    // Internal cache settings
    //
    // The main cache directory
    // Use '' (empty string) to disable the internal cache
    'cache_path' => '/var/www/example.com/htdocs/temp',

    // Used as the subdirectory of the cache_path directory,
    // where cache items will be stored
    'cache_name' => 'assets-cache',

    // The lifetime (in seconds) for cache items
    // With a value 0 causing items to be stored indefinitely
    'cache_lifetime' => 0,

    // Enable JavaScript and CSS compression
    // 1 = on, 0 = off
    'minify' => 1
];

// Register asset extension
$engine->loadExtension(new PlatesAssetExtension(new AssetEngine($engine, $options)));
```

Usage
-----

[](#usage)

### The page template

[](#the-page-template)

Template file: `index.php`

```

```

### Render a template

[](#render-a-template)

```
$engine = new League\Plates\Engine('/path/to/templates');

echo $engine->render('index', ['baseUrl' => '']);
```

### The result

[](#the-result)

```
DOCTYPE html>

    Demo

@media print{.noprint{display:none}.navbar{visibility:hidden;display:none}.container{width:99%}.table{table-layout:fixed;width:99%;max-width:99%}}

```

#### Parameters

[](#parameters)

1. Parameter: $assets

NameTypeDefaultRequiredDescriptionfilesarray\[\]yesAll assets (files) to be delivered to the browser. [Plates Folders](https://platesphp.com/v3/engine/folders/) (`myalias::myfile.js`) are also supported.2. Parameter: $options

NameTypeDefaultRequiredDescriptioninlineboolfalsenoDefines whether the browser downloads the assets inline or via URL.minifybooltruenoSpecifies whether JS/CSS compression is enabled or disabled.namestringfilenoDefines the output file name within the URL.Slim 4 integration
------------------

[](#slim-4-integration)

For this example we use the [PHP-DI](http://php-di.org/) package.

Add the container definition:

```
