Installation:
composer require akuma/bootswatch-bundle:dev-master
Add the bundle to AppKernel.php:
new Akuma\Bundle\BootswatchBundle\AkumaBootswatchBundle(),
Configure (config.yml):
akuma_bootswatch:
theme: "cosmo" # Default theme (e.g., "cerulean", "flatly")
font_awesome: true
Install Assets:
php bin/console akuma:bootswatch:install
This copies Bootswatch assets to web/ and sets up Font Awesome.
First Use Case:
Include the theme in your base template (base.html.twig):
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ asset('css/bootswatch/{{ app.config.akuma_bootswatch.theme }}.min.css') }}">
Dynamic Theme Selection: Override the theme per environment or route:
# config_dev.yml
akuma_bootswatch:
theme: "cerulean"
Or dynamically in a controller:
$this->get('akuma_bootswatch.twig.extension')->setTheme('flatly');
Twig Extension:
Use the akuma_bootswatch Twig extension to generate theme-specific assets:
{{ akuma_bootswatch.css('bootswatch/{{ theme }}.min.css') }}
Assetic Integration:
Enable Assetic in config (auto_configure.assetic: true) and bundle assets:
// app/config/config.yml
assetic:
bundles: [AcmeDemoBundle]
Use in Twig:
{% stylesheets
'bundles/acmedemobundle/css/bootstrap.min.css'
'bundles/acmedemobundle/css/bootswatch/{{ theme }}.min.css'
filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
Custom Output Paths: Redirect assets to a CDN or subdirectory:
akuma_bootswatch:
output_dir: "%kernel.root_dir%/../web/custom-assets"
Compile on Demand:
Configure a processor (e.g., scssphp):
akuma_bootswatch:
less_filter: "scssphp"
Recompile assets:
php bin/console assetic:dump --watch
Custom Sass Variables:
Override Bootswatch variables by extending its Sass files in your project’s scss/ directory.
install command copies Font Awesome to web/fonts. Use it in Twig:
<link rel="stylesheet" href="{{ asset('css/font-awesome.min.css') }}">
Asset Paths:
akuma:bootswatch:install, verify assets are in web/css/bootswatch/ and web/fonts/.php bin/console cache:clear
Theme Not Loading:
"cosmo", not "Cosmo").config.yml for typos in bootswatch.theme.Assetic Conflicts:
auto_configure.assetic: true and bundles are properly configured.php bin/console assetic:dump --debug
Sass/Less Dependencies:
scssphp or less.php will break compilation. Install dev dependencies:
composer require --dev leafo/scssphp oyejorge/less.php
$this->get('akuma_bootswatch.config')->getConfig();
akuma:bootswatch:install with -v for verbose output:
php bin/console akuma:bootswatch:install -v
Custom Themes:
vendor/thomaspark/bootswatch to web/css/bootswatch/ and update config.yml:
akuma_bootswatch:
bootswatch:
path: "%kernel.root_dir%/../web/css/bootswatch"
Override Twig Extensions:
// src/Acme/DemoBundle/Twig/BootswatchExtension.php
class BootswatchExtension extends \Akuma\Bundle\BootswatchBundle\Twig\BootswatchExtension
{
public function getThemeClass($theme) { ... }
}
Post-Install Hooks:
akuma:bootswatch:install:
# config.yml
akuma_bootswatch:
post_install_command: "app/console my:custom-task"
http_cache for Bootswatch assets:
assetic:
use_controller: true
filters:
http_cache:
assets_path: /assets
yui_css or yui_js2 filters for production:
{% stylesheets '...' filter='yui_css2' %}
How can I help you explore Laravel packages today?