PHPCRAssets
, (*1)
Bundle for storing and serving js, css assets with PHPCR Storage., (*2)
Install
Include this to you composer.json file, (*3)
``` js
"nvbooster/phpcr-assets-bundle": "dev-master", (*4)
or run
```sh
composer require nvbooster/phpcr-assets-bundle-master
Ensure CmfRoutingAutoBundle is installed and configured according to https://github.com/symfony-cmf/RoutingAutoBundle, (*5)
Then add PHPCRAssetsBundle to your AppKernel:, (*6)
public function registerBundles()
{
$bundles = array(
...
new NVBooster\PHPCRAssetsBundle\NVBoosterPHPCRAssetsBundle(),
);
}
No configuration required for base functionality;, (*7)
SonataAdmin integration
To manage assets using SonataAdmin add admin services to sonata config, (*8)
sonata_admin:
dashboard:
groups:
...
assets:
label: Assets
items:
- nvbooster_assets.js_asset_admin
- nvbooster_assets.css_asset_admin
sonata_doctrine_phpcr_admin:
document_tree:
...
NVBooster\PHPCRAssetsBundle\Asset\JsAsset:
valid_children: []
NVBooster\PHPCRAssetsBundle\Asset\CssAsset:
valid_children: []
CodeMirror integration
To use CodeMirror library for editing assets in SonataAdmin, add codemirror section to config:, (*9)
nvbooster_assets:
codemirror: ~
If you want for bundle to automatically include js and css files of CodeMirror when needed, then you should provide paths (see Full config)., (*10)
Full configuration
nvbooster_assets:
phpcr:
root_path: '/cms/assets' #Defines path in PHPCR tree for assets to store in
filters:
css: [] #Default assetics filters for css assets
js: [] #Default assetics filters for js assets
routing:
base_uri: assets #Defines base uri for routes generated
codemirror:
paths:
js: ~ #Path for codemirror.js in web folder
css: ~ #Path for codemirror.css in web folder
modes_dir: ~ #Path for codemirror modes directory in web folder
themes_dir: ~ #Path for codemirror theme styles in web folder
options: #Codemirror widget defaults
mode: xml #Default mode
theme: eclipse #Default theme
Using
After configuring run repository initializers to create all required paths in PHPCR storage:, (*11)
php app/console doctrine:phpcr:repository:init
Include assets in your templates:, (*12)
<link rel="stylesheet" href="{{ url(css_asset) }}"/>
<script type="text/javascript" src="{{ url(js_asset) }}"></script>
or any other way., (*13)