bmatzner/jquery-mobile-bundle
Installation:
Run composer require bmatzner/jquery-mobile-bundle:^1.4 and update dependencies.
Register the bundle in AppKernel.php under $bundles.
Asset Setup:
Execute php app/console assets:install web (or --symlink for development).
Verify assets appear in web/bundles/bmatznerjquerymobile/.
First Use Case: Include jQuery Mobile in a Twig template:
{# app/Resources/views/base.html.twig #}
<link rel="stylesheet" href="{{ asset('bundles/bmatznerjquerymobile/css/jquery.mobile.min.css') }}">
<script src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
<script src="{{ asset('bundles/bmatznerjquerymobile/js/jquery.mobile.min.js') }}"></script>
Add a basic jQuery Mobile page structure:
<div data-role="page" id="home">
<div data-role="header">Header</div>
<div data-role="content">Content</div>
</div>
Theming: Override the default theme by extending the CSS bundle:
<link rel="stylesheet" href="{{ asset('bundles/bmatznerjquerymobile/css/themes/default/jquery.mobile.theme.min.css') }}">
Customize via SASS (compile locally) or inline styles.
Dynamic Page Loading: Use jQuery Mobile’s AJAX navigation:
// app/Resources/public/js/app.js
$(document).on('pagebeforechange', function(e, data) {
if (data.toPage.attr('data-role') === 'page') {
// Preload or modify content
}
});
Symfony Integration:
<a href="{{ path('app_home') }}" data-role="button">Home</a>
// src/AppBundle/Controller/MobileController.php
public function homeAction(Request $request) {
return $this->render('mobile/home.html.twig');
}
Asset Management:
--symlink to avoid asset duplication.assets:install --no-debug.{% if app.request.headers.get('User-Agent') matches '/Mobile|Android|iPhone/i' %}
{# Include jQuery Mobile assets #}
{% endif %}
Asset Paths:
assets:install.{{ asset() }} with the correct bundle path (e.g., bundles/bmatznerjquerymobile/).jQuery Conflicts:
<script src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
Deprecated Features:
data-transition="none" is limited).Symfony 4+ Compatibility:
config/bundles.php:
return [
// ...
Bmatzner\JQueryMobileBundle\BmatznerJQueryMobileBundle::class => ['all' => true],
];
Uncaught ReferenceError (missing jQuery) or jQuery is not defined (incorrect load order)./bundles/bmatznerjquerymobile/.... Use --symlink in dev to avoid cache issues.Custom Themes:
Override the default theme by copying bundles/bmatznerjquerymobile/css/themes/default/ to your project and modifying it.
JavaScript Extensions: Add custom scripts after jQuery Mobile’s initialization:
<script src="{{ asset('bundles/bmatznerjquerymobile/js/jquery.mobile.min.js') }}"></script>
<script src="{{ asset('js/custom-mobile.js') }}"></script>
Asset Versioning: Append a query string to bust caches in development:
<script src="{{ asset('bundles/bmatznerjquerymobile/js/jquery.mobile.min.js?v='~app.version) }}"></script>
!important. Override with higher specificity or !important in your CSS.How can I help you explore Laravel packages today?