Installation:
composer.json:
"require": {
"bmatzner/jquery-bundle": "~1.12"
}
composer update bmatzner/jquery-bundle.AppKernel.php:
new Bmatzner\JQueryBundle\BmatznerJQueryBundle(),
php app/console assets:install web
First Use Case:
<script src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
<script>
$(document).ready(function() {
alert('jQuery is working!');
});
</script>
master branch).bundles/bmatznerjquery/js/.assets:install is run post-installation.Twig Integration:
asset() function to reference jQuery files dynamically:
{% block javascripts %}
<script src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
<script src="{{ asset('bundles/bmatznerjquery/js/jquery-migrate.min.js') }}"></script>
{% endblock %}
Version-Specific Configuration:
master branch:
composer require bmatzner/jquery-bundle:dev-master
2.x branch (lighter, no legacy support).Asset Optimization:
assetic or webpack-encore to bundle jQuery with other JS files:
# config/packages/assetic.yaml
assetic:
bundles: [BmatznerJQueryBundle]
assets:install with --symlink for development:
php app/console assets:install web --symlink
Dependency Management:
<script src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
<script src="{{ asset('bundles/yourbundle/js/your-plugin.js') }}"></script>
$(document).ready(function() {
$('form').on('submit', function(e) {
if (!$(this).valid()) e.preventDefault();
});
});
$.ajax({
url: "{{ path('api_endpoint') }}",
method: 'GET',
success: function(data) { /* ... */ }
});
$(document).on('click', '.dynamic-button', function() { /* ... */ });
Asset Path Errors:
bundles/bmatznerjquery/js/jquery.min.js not found after installation.assets:install and verify the web/bundles/bmatznerjquery/ directory exists.composer.json for correct version constraints (e.g., ~1.12 vs. dev-master).jQuery Conflicts:
asset() consistently.Legacy Browser Support:
master branch explicitly:
composer require bmatzner/jquery-bundle:dev-master
Caching Issues:
php app/console cache:clear --env=prod
var/cache/ for stale files.console.log() or browser dev tools to verify jQuery is loaded:
console.log(jQuery.fn.jquery); // Should output "1.12.2" or similar.
composer.json requirements.Custom Builds:
web/bundles/bmatznerjquery/js/ (Symfony’s asset system will prioritize local files).jquery.custom.min.js file and reference it in Twig.Plugin Integration:
composer.json:
"require": {
"bmatzner/jquery-bundle": "~1.12",
"components/jqueryui": "^1.12"
}
<script src="{{ asset('bundles/components/jqueryui/jquery-ui.min.js') }}"></script>
Configuration:
config/packages/bmatzner_jquery.yaml (if supported in newer versions). For this bundle, manual Twig overrides are typical:
# Example (hypothetical; verify bundle docs)
bmatzner_jquery:
version: 3.x # If customizable
Testing:
WebTestCase to verify jQuery functionality:
public function testJQueryLoads()
{
$client = static::createClient();
$client->request('GET', '/');
$this->assertContains('jquery.min.js', $client->getResponse()->getContent());
}
How can I help you explore Laravel packages today?