ibr / web-asset-loader
Nette extension for loading JS and CSS into template.
1.0.0
2017-02-24 20:08 UTC
Requires
- php: >= 5.4.0
- nette/application: ~2.3
- nette/di: ~2.3
This package is not auto-updated.
Last update: 2025-07-20 01:03:02 UTC
README
Nette extension for loading JS and CSS into template.
Assets gets loaded into the page in the exact order as you define it. This is useful for loading libraries (jQuery) first or overriding css.
Installation
You can install WebAssetLoader using Composer:
composer require ibr/web-asset-loader
Example with Nette Framework extension
Configuration in config.neon
extensions: webAssetLoader: IBR\WebAssetLoader\Nette\Extension webAssetLoader: js: - path/to/file/file1.js - path/to/file/file2.js css: - path/to/file/file1.css - path/to/file/file2.css
Usage in BasePresenter.php
(need to pass the instance of the control and create component)
use \IBR\WebAssetLoader\Loader as WebAssetLoader; abstract class BasePresenter extends \Nette\Application\UI\Presenter { /** * @var WebAssetLoader * @inject */ public $webAssetLoader; public function createComponentWebAssetLoader() { return $this->webAssetLoader; } }
Usage in @layout.latte
(or any template)
{control webAssetLoader:css} {control webAssetLoader:js}
Result
<link rel="stylesheet" href="{$basePath}/path/to/file/file1.css"> <link rel="stylesheet" href="{$basePath}/path/to/file/file2.css"> <script type="text/javascript" src="{$basePath}/path/to/file/file1.js"></script> <script type="text/javascript" src="{$basePath}/path/to/file/file2.js"></script>