Installation:
composer require bmatzner/jquery-ui-bundle
Add the bundle to app/AppKernel.php under $bundles.
Asset Installation:
php app/console assets:install web --symlink
(Replace web with your public directory if different.)
First Use Case: Include jQuery UI in a Twig template:
{# app/Resources/views/base.html.twig #}
<link rel="stylesheet" href="{{ asset('bundles/bmatznerjqueryui/css/smoothness/jquery-ui.css') }}">
<link rel="stylesheet" href="{{ asset('bundles/bmatznerjqueryui/css/smoothness/jquery.ui.theme.css') }}">
<script src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
<script src="{{ asset('bundles/bmatznerjqueryui/js/minified/jquery-ui.min.js') }}"></script>
Initialize a widget (e.g., datepicker) in a JS file:
$(document).ready(function() {
$("#datepicker").datepicker();
});
Theming:
smoothness, redmond, etc.) or add custom themes by placing CSS files in web/bundles/bmatznerjqueryui/css/.<link rel="stylesheet" href="{{ asset('bundles/bmatznerjqueryui/css/custom-theme/jquery-ui.css') }}">
Lazy Loading:
{% if is_granted('ROLE_ADMIN') %}
<script src="{{ asset('bundles/bmatznerjqueryui/js/minified/jquery-ui.min.js') }}"></script>
{% endif %}
Widget Initialization:
app/Resources/public/js/jquery-ui-init.js) and include them conditionally:
// app/Resources/public/js/jquery-ui-init.js
$(document).ready(function() {
$("#sortable-list").sortable();
$("#draggable-item").draggable();
});
<script src="{{ asset('js/jquery-ui-init.js') }}"></script>
Symfony Forms Integration:
{{ form_widget(form.dateField, {'attr': {'class': 'datepicker'}}) }}
$(document).ready(function() {
$(".datepicker").datepicker();
});
Asset Versioning:
<script src="{{ asset('bundles/bmatznerjqueryui/js/minified/jquery-ui.min.js?v=' ~ '1.10.3') }}"></script>
Asset Paths:
web/bundles/. If using a custom public directory (e.g., public/), update the paths in Twig or reconfigure assets:install.{{ asset('bundles/bmatznerjqueryui/...') }} and adjust if needed.jQuery Dependency:
symfony/webpack-encore) also loads jQuery.noConflict():
var jQueryUI = $.noConflict(true);
jQueryUI(document).ready(function() { ... });
Theme Overrides:
web/bundles/bmatznerjqueryui/css/ and referenced correctly. The bundle does not auto-detect custom themes.jquery-ui.css + jquery.ui.theme.css).Outdated Version:
web/bundles/bmatznerjqueryui/ and update references.Asset Installation:
assets:install without --symlink copies files, which can bloat your project. Symlinks are preferred for development.--symlink in development and switch to copies for production if needed.Check Asset Paths:
Console Errors:
$ is not defined → jQuery not loaded.Cannot read property 'datepicker' of undefined → jQuery UI not loaded or initialized after DOM ready.Conflict Detection:
console.log($.fn.jquery) to verify jQuery version and console.log($.ui.version) to check jQuery UI version.Custom Widgets:
jquery-ui.timepicker.js) in web/bundles/bmatznerjqueryui/js/.Twig Extensions:
// src/Twig/AppExtension.php
class AppExtension extends \Twig_Extension
{
public function getFunctions()
{
return [
new \Twig_SimpleFunction('jquery_ui_asset', [$this, 'getAssetPath']),
];
}
public function getAssetPath($path)
{
return $this->env->getExtension('asset')->getUrl('bundles/bmatznerjqueryui/' . $path);
}
}
Usage in Twig:
<link rel="stylesheet" href="{{ jquery_ui_asset('css/smoothness/jquery-ui.css') }}">
Configuration:
config.yml:
bmatzner_jquery_ui:
theme: 'custom-theme'
(Note: Requires extending the bundle or patching the template logic.)Webpack Encore Integration:
// webpack.config.js
Encore
.addEntry('jquery-ui', './vendor/bmatzner/jquery-ui-bundle/Resources/public/js/jquery-ui.min.js')
.copyFiles({
from: './vendor/bmatzner/jquery-ui-bundle/Resources/public/css/smoothness',
to: 'css/[path][name].[ext]',
});
How can I help you explore Laravel packages today?