Creating a Section
A section is a configurable UI component used to compose templates in Bagisto Visual. Basically a section is just a Blade or Livewire component that defines structure, behavior, settings, and rendering logic.
Generate a Section
To generate a new section, use the visual:make-section
Artisan command:
php artisan visual:make-section AnnouncementBar --theme=awesome-theme
This will create a basic Blade section class named AnnouncementBar inside the awesome-theme package:
packages/Themes/AwesomeTheme/src/Sections/AnnouncementBar.php
Generated class content:
<?php
namespace YourVendor\AwesomeTheme\Sections;
use BagistoPlus\Visual\Sections\BladeSection;
class AnnouncementBar extends BladeSection
{
protected static string $view = 'shop::sections.announcement-bar';
public static function settings(): array
{
return [];
}
public static function blocks(): array
{
return [];
}
}
It also generates the corresponding Blade view file:
packages/Themes/AwesomeTheme/resources/views/sections/announcement-bar.blade.php
Default Blade content:
<div>
Announcement Bar
</div>
INFO
Ensure the theme is already installed:
composer require themes/awesome-theme
--livewire
Use this flag to generate a Livewire-based section:
php artisan visual:make-section AnnouncementBar --livewire --theme=awesome-theme
This creates a class that extends LivewireSection and includes a Livewire component stub.
No --theme
If omitted, the section is placed in:
app/Visual/Sections/AnnouncementBar.php
Registering Sections
Bagisto Visual automatically discovers sections from:
app/Visual/Sections
packages/<Vendor>/<Theme>/src/Sections
For other locations, you can manually register sections in a service provider:
Discover a directory
Visual::discoverSectionsIn(base_path('modules/Shared/Sections'));
Packages: use a vendor prefix
Visual::discoverSectionsIn(
base_path('modules/Shared/Sections'),
'vendor-prefix'
);
Register a single class
Visual::registerSection(\App\Custom\Sections\PromoBanner::class);
Theme packages: use a vendor prefix
Visual::registerSection(
\Themes\AwesomeTheme\Sections\AnnouncementBar::class,
'awesome-theme'
);
This ensures that multiple themes can define sections with the same slug without conflict.
Next: Section Attributes