Download the PHP package craftsnippets/static-file-manager without Composer
On this page you can find all versions of the php package craftsnippets/static-file-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download craftsnippets/static-file-manager
More information about craftsnippets/static-file-manager
Files in craftsnippets/static-file-manager
Package static-file-manager
Short Description Keep your static files list in PHP configuration file.
License MIT
Informations about the package static-file-manager
Static file manager
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require craftsnippets/static-file-manager
- In the Control Panel, go to Settings → Plugins and click the “Install” button for asset manifest.
Overview
- This plugin allows you to keep the list of CSS, JS and Favicon files in PHP configuration file instead of Twig templates.
- You can inject files from config file into frontend site and into control panel.
CSS and JS files will be injected into proper places - CSS files to end of
<head>
and JS files at end of<body>
. - You can also include links to google fonts CSS files, like
https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400&display=swap
- it will be included like other CSS files. - Plugin also allows for cache busting of files by appending URL parameter to their paths which contains their modification date. This means that files will be cache busted only if they were modified. Files from external servers won't be cache busted.
- Plugin exposes endpoint that lists all static files in JSON format, so the list can be consumed by frontend build tools. This does not include google fonts files.
Usage
In order to use plugin, place this code into base template of your project. Remember that static files won't be inserted is there is no <body>
or <head>
tags in your template.
You can pass variable set to false
to this function to cancel injection of assets into template:
Files list to inject is set in config/static-file-manager.php
setting file, under filesList
setting. To inject files into control panel, place them into cpFileList
setting. All file paths are relative to the web root.
Here is example config file:
You can use inline php function to dynamically define injected file name:
Twig filter
You can manually bust cache of files within Twig templates using version
filter:
JSON endpoint
Plugin exposes endpoint that returns asset list in JSON format. The list consists of two arrays - array with key css
contains CSS files and array with key js
contains Javascript files. Only files present on the filesystem are listed, so these from external servers are omitted from this list. List is available under [website url]/actions/static-file-manager
URL, but you first need to enable it using exposeJsonList
config setting.
Here's an example gulp task that loads list of Javascript files from endpoint and minifies them into one file. This config assumes that you use xampp and your project lives in htdocs
directory.
Settings
Place these settings in config/static-file-manager.php
file.
filesList
- array with list of static files paths within web root directory (usuallyweb
directory). These files will be injected into frontend site.cpFileList
- array with list of static files within web root directory that will be injected into control panel.faviconPath
- path to favicon file.cpFaviconPath
- path to control panel favicon file.bustCache
- if files should be cache busted. Default:true
.exposeJsonList
- if plugin should expose list of files in JSON format. Default:false
.
Brought to you by Piotr Pogorzelski