📜 ⬆️ ⬇️

Improved plugin for Smarty - Combine

The plugin allows you to collect and minimize several CSS or Javascript files together.
image
My plugin is just a refinement of the plugin from this post. Plugin for Smarty - Combine
Find out what's new in the plugin and how it works under the cat


The plugin works quite simply: when one of the included files changes, it creates a new output file and returns the path to it.

You might ask: “What did I add?”. And the answer is simple, file minimization has been added to the work of the plugin. Now the files are not just glued together, but also minified with Minify . In addition, the ability to disable file bonding and minification is added, which is convenient for developer development.
')
The plugin has a list of four input parameters:
  1. input , which is a simple array containing a list of paths to the files being glued together;
  2. output , which is the path to the output file;
  3. age , the time in seconds between checking for changes to one of the included files. This parameter can be omitted, by default it is 3600 seconds.
  4. debug , turns on debug mode. When enabled, debugging does not compile or minimize files, but gives a complete list of files. This parameter can be omitted; it defaults to false.


Source

The code is available on github .

Connection pattern in pattern

Smarty 3 has the ability to create an array on the fly, so the code is given with this feature in mind.

{combine input = array ('/ js / core.js',' / js / slideviewer.js') output = '/ js / big.js' age = '30' debug = false}


For Smarty 2, the array must be passed through a separate variable.

In the php file, we create our variable with an array of files.
$ js_filelist = array ('/ js / core.js', '/ js / slideviewer.js');
$ smarty_object-> assign ('js_files', $ js_filelist);


In the template file we connect
{combine input = $ js_files output = '/ cache / big.js' age = '30' debug = false}


There are several nuances when using the plugin. The path to the files should go from document_root, and the folder with the output file should allow writing and creating new files. You cannot combine CSS and JS files at the same time.

Source: https://habr.com/ru/post/266291/


All Articles