Installation:
src/Awaresoft directory and symlink it (as per the README).composer.json includes the bundle in require (or manually symlink BannerBundle to /src/Awaresoft/BannerBundle).php bin/console cache:clear
Enable the Bundle:
Add to config/bundles.php:
return [
// ...
Awaresoft\BannerBundle\AwaresoftBannerBundle::class => ['all' => true],
];
First Use Case:
{{ render(controller('AwaresoftBannerBundle:Default:block')) }}
/admin/banner.Banner Creation:
/admin/banner) to define banners (title, content, visibility rules).# config/packages/awaresoft_banner.yaml
awaresoft_banner:
visibility:
- { route: 'homepage', priority: 10 }
- { route: 'product.*', priority: 5 }
Dynamic Rendering:
BannerManager service to fetch banners programmatically:
use Awaresoft\BannerBundle\Manager\BannerManager;
class MyController {
public function __construct(private BannerManager $bannerManager) {}
public function showHomepage() {
$banners = $this->bannerManager->getVisibleBanners();
// Render in Twig: {{ dump(banners) }}
}
}
Twig Integration:
{% block banner_area %}
{% for banner in banners %}
<div class="banner">
{{ banner.content|raw }}
</div>
{% endfor %}
{% endblock %}
Fixtures:
use Awaresoft\BannerBundle\Entity\Banner;
public function load(ObjectManager $manager) {
$banner = new Banner();
$banner->setTitle('Promo');
$banner->setContent('<h1>Sale!</h1>');
$manager->persist($banner);
}
Symfony 2.x Dependency:
make:controller).Sonata Admin Quirks:
sonata_block.yaml:
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
awaresoft_banner.block.banner:
contexts: [admin, frontend]
ca:cl) if blocks fail to render.Visibility Logic:
$this->bannerManager->getVisibleBanners('homepage'); // Explicit route check
Database Schema:
Banner entity manually.Log Visibility Rules:
Enable debug mode and inspect BannerManager logs for skipped banners.
$this->bannerManager->setDebug(true);
Twig Debug: Dump banners in templates:
{{ dump(app.container.get('awaresoft_banner.manager').getVisibleBanners()) }}
Custom Visibility Rules:
Extend Awaresoft\BannerBundle\Visibility\VisibilityRuleInterface:
class IpVisibilityRule implements VisibilityRuleInterface {
public function isVisible(Banner $banner, Request $request) {
return $request->getClientIp() === '127.0.0.1';
}
}
Register in services.yaml:
services:
app.banner.ip_rule:
class: App\Banner\IpVisibilityRule
tags: [awaresoft_banner.visibility_rule]
Override Templates:
Copy AwaresoftBannerBundle:Default:block.html.twig to templates/bundles/AwaresoftBanner/Default/block.html.twig.
Event Listeners:
Hook into banner.pre_render or banner.post_save via Symfony events:
services:
app.banner.listener:
class: App\Banner\BannerListener
tags:
- { name: kernel.event_listener, event: awaresoft_banner.pre_render, method: onPreRender }
How can I help you explore Laravel packages today?