Skip to content

Commit fad22f3

Browse files
committed
Improve docs
1 parent 5d18914 commit fad22f3

File tree

2 files changed

+451
-210
lines changed

2 files changed

+451
-210
lines changed

README.md

Lines changed: 71 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ while providing content editors with an intuitive interface for managing pages a
2020
- **Ready-to-use admin interface** - Pre-configured Filament panel with all resources and management tools
2121
- **Developer-friendly** - Extendable models & tables, customizable templates, and comprehensive configuration options
2222
- **Content organization** - Tag system, hierarchical page structure, and settings management
23+
- **Works out-of-the-box** - Get the package quickly up and running, while focussing on easy configuration, customisation & extendability.
2324

2425
## Additional Features
2526

@@ -124,7 +125,8 @@ If you want translated content and routes, go through the following steps:
124125

125126
### Routes
126127

127-
Register the routes in your route file, probably `web.php`:
128+
Register the routes in your route file, probably `web.php`.
129+
Best at the bottom of the file, since the pages routes with slugs will catch many urls.
128130

129131
```php
130132
\Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages::routes();
@@ -169,6 +171,23 @@ The package includes a powerful hierarchical menu builder with a drag-and-drop i
169171
- **Icon support** - Optional icons for menu items (basic implementation currently)
170172
- **Dynamic labels** - Use model titles or custom labels for linked content
171173

174+
### Adding a menu to Blade
175+
176+
The package includes a `default` built-in menu style which is developed in a generic way so that you can tweak its styling by passing some attributes without having to publish the corresponding blade templates.
177+
178+
Example usage to have a horizontal menu using tailwind:
179+
```blade
180+
<x-flexible-pages-menu
181+
code="HEADER"
182+
style="default"
183+
ulClass="flex flex-row justify-start items-center gap-x-4"
184+
itemLinkClass="text-black hover:text-primary hover:underline"
185+
currentItemLinkClass="text-grey hover:no-underline"
186+
/>
187+
```
188+
189+
See the file `../tailwind/components/menu/default.blade.php` for all possible attributes.
190+
172191
### Adding linkable models
173192

174193
To make your models available in the menu builder, add them to the configuration:
@@ -204,63 +223,17 @@ class Product extends Model implements HasMenuLabel
204223
If you are using the Flexible Content Blocks title trait in your model, you can implement `HasMenuLabel`
205224
easily with [`HasTitleMenuLabelTrait`](src/Models/Concerns/HasTitleMenuLabelTrait.php).
206225

207-
### Using the 'default' menu style
208-
209-
The package includes a `default` built-in menu style which is developed in a generic way so that you can tweak its styling by passing some attributes without having to publish the corresponding blade templates.
210-
211-
Example usage to have a horizontal menu using tailwind:
212-
```blade
213-
<x-flexible-pages-menu
214-
code="HEADER"
215-
style="default"
216-
ulClass="flex flex-row justify-start items-center gap-x-4"
217-
itemLinkClass="text-black hover:text-primary hover:underline"
218-
currentItemLinkClass="text-grey hover:no-underline"
219-
/>
220-
```
221-
222-
See the file `../tailwind/components/menu/default.blade.php` for all possible attributes.
223-
224-
### Customizing additional menu styles
225-
226-
If needed, you can easily add your own menu styles in addition to the `default` style, e.g. the 'mega' menu style:
227-
228-
1. **Add new styles to config:**
229-
```php
230-
// config/filament-flexible-content-block-pages.php
231-
'menu' => [
232-
'styles' => [
233-
'default',
234-
'mega', // Your custom style
235-
],
236-
],
237-
```
238-
**Tip:** Add translations if you want UX-friendly style dropdowns.
239-
240-
2. **Create the template files:**
241-
```bash
242-
# Main menu template
243-
resources/views/vendor/filament-flexible-content-block-pages/tailwind/components/menu/mega.blade.php
244-
245-
# Menu item template
246-
resources/views/vendor/filament-flexible-content-block-pages/tailwind/components/menu/mega-item.blade.php
247-
```
248-
249-
3. **Use in your templates:**
250-
```blade
251-
<x-flexible-pages-menu code="HEADER" style="mega" />
252-
```
253-
254-
The style can also be configured in the database model, then you can skip the `style` attribute.
255-
256226
### Menu seeding
257227

258228
It makes a lot of sense to create most of the menu's in seeders, so they can be automatically synced over different environments.
259229
See the [menu seeding documentation](documentation/seeders.md) for programmatic menu creation.
260230

231+
For creating custom menu styles and advanced menu customization, see the [menu customization documentation](documentation/extending-and-customisation.md#menu).
232+
261233
## Settings
262234

263235
All settings are stored in one table in one record. The reason is to be able to add spatie medialibrary media as a config value.
236+
Each setting is cached and refreshed when the settings change.
264237

265238
### Use settings
266239

@@ -280,62 +253,59 @@ $seoImageHtml = Settings::imageHtml(Settings::COLLECTION_DEFAULT_SEO, Settings::
280253
$settings = Settings::getSettings();
281254
```
282255

283-
### Extend settings
256+
To add custom settings fields and extend the settings functionality, see the [settings extension documentation](documentation/extending-and-customisation.md#settings).
257+
258+
## Routing
259+
260+
The package provides a flexible routing system that supports hierarchical page structures and multilingual sites.
261+
262+
### URL Structure
263+
264+
Pages are organized in a three-level hierarchy:
265+
- **Root pages**: `/about`, `/contact`
266+
- **Child pages**: `/services/web-development`
267+
- **Grandchild pages**: `/services/web-development/laravel`
284268

285-
To add custom settings fields:
269+
### Route Registration
270+
271+
Register the package routes in your `web.php` file. Place this at the **bottom** of your routes file since page routes with slugs will catch many URLs:
286272

287-
1. **Create a migration** to add new columns:
288273
```php
289-
Schema::table(FilamentFlexibleContentBlockPages::config()->getSettingsTable(), function (Blueprint $table) {
290-
$table->string('custom_field')->nullable();
291-
$table->json('translatable_field')->nullable(); // for translatable fields
292-
});
274+
// At the bottom of routes/web.php
275+
\Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages::routes();
293276
```
294277

295-
2. **Extend the Settings model** by adding constants for easy referral and updating `$translatable`, if needed:
278+
### Generating URLs
279+
280+
Use the facade to generate URLs for pages:
281+
296282
```php
297-
class CustomSettings extends \Statikbe\FilamentFlexibleContentBlockPages\Models\Settings
298-
{
299-
const SETTING_CUSTOM_FIELD = 'custom_field';
300-
301-
protected $translatable = [
302-
parent::SETTING_FOOTER_COPYRIGHT,
303-
parent::SETTING_CONTACT_INFO,
304-
self::SETTING_CUSTOM_FIELD, // if translatable
305-
];
306-
}
283+
use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages;
284+
285+
// Generate URL for a page
286+
$url = FilamentFlexibleContentBlockPages::getUrl($page);
287+
288+
// Generate URL for a specific locale
289+
$url = FilamentFlexibleContentBlockPages::getUrl($page, 'en');
307290
```
308291

309-
3. **Extend the SettingsResource** by overriding `getExtraFormTabs()`:
310-
```php
311-
class CustomSettingsResource extends \Statikbe\FilamentFlexibleContentBlockPages\Resources\SettingsResource
312-
{
313-
protected static function getExtraFormTabs(): array
314-
{
315-
return [
316-
Tab::make('Custom Tab')->schema([
317-
TextInput::make(CustomSettings::SETTING_CUSTOM_FIELD)
318-
->label('Custom Field')
319-
->required(),
320-
]),
321-
];
322-
}
323-
}
292+
In Blade templates:
293+
```blade
294+
<a href="{{ \Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages::getUrl($page) }}">
295+
{{ $page->title }}
296+
</a>
324297
```
325298

326-
4. **Configure the extended model and resource** in your config file:
327-
```php
328-
// config/filament-flexible-content-block-pages.php
329-
'models' => [
330-
// ...
331-
'settings' => \App\Models\CustomSettings::class,
332-
],
299+
### Route Helpers
333300

334-
'resources' => [
335-
// ...
336-
'settings' => \App\Resources\CustomSettingsResource::class,
337-
],
338-
```
301+
The package includes two route helper implementations:
302+
303+
- **`PageRouteHelper`**: For non-multilingual sites with simple URLs
304+
- **`LocalisedPageRouteHelper`**: For multilingual sites with localized URLs (e.g., `/en/about`, `/nl/over-ons`)
305+
306+
Configure which helper to use in your [configuration file](documentation/configuration.md#route-helper).
307+
308+
For advanced routing customization, custom route helpers, and controller extensions, see the [routing customization documentation](documentation/extending-and-customisation.md#routes).
339309

340310
## Redirects
341311

@@ -376,52 +346,11 @@ The package includes an automatic sitemap generator that creates XML sitemaps fo
376346
- **Dynamic change frequency** - Based on last modification date (weekly, monthly, yearly)
377347
- **Flexible content inclusion** - Pages, routes, linkable models, and custom URLs
378348
- **URL exclusion patterns** - Skip specific URLs or patterns from the sitemap
379-
- **SEO optimization** - Includes last modification dates and proper XML structure
380-
381-
### Configuration
382-
383-
Enable and configure the sitemap generator in your config file:
384-
385-
```php
386-
// config/filament-flexible-content-block-pages.php
387-
'sitemap' => [
388-
'enabled' => true,
389-
'generator_service' => \Statikbe\FilamentFlexibleContentBlockPages\Services\SitemapGeneratorService::class,
390-
'method' => SitemapGeneratorMethod::MANUAL, // MANUAL, CRAWL, or HYBRID
391-
'include_pages' => true,
392-
'include_link_routes' => true,
393-
'include_linkable_models' => true,
394-
'exclude_patterns' => [
395-
'/admin/*',
396-
'/api/*',
397-
],
398-
'custom_urls' => [
399-
'https://example.com/special-page',
400-
],
401-
],
402-
```
403-
404-
### Generation Methods
405-
406-
**Manual** (`SitemapGeneratorMethod::MANUAL`):
407-
- Generates sitemap based on database content (pages, routes, models)
408-
- Faster and more predictable
409-
- Best for most use cases
410-
411-
**Crawl** (`SitemapGeneratorMethod::CRAWL`):
412-
- Crawls your website to discover URLs
413-
- May find URLs not in your database
414-
- Slower but comprehensive
415-
- Requires chromium
416-
417-
**Hybrid** (`SitemapGeneratorMethod::HYBRID`):
418-
- Combines both approaches
419-
- Crawls first, then adds manual entries
420-
- Most comprehensive but slowest
421349

422350
### Usage
423351

424-
Generate the sitemap manually:
352+
Make sure the sitemap is enabled in the [configuration](documentation/configuration.md#sitemap-configuration).
353+
Generate the sitemap manually by running:
425354

426355
```bash
427356
php artisan flexible-content-block-pages:generate-sitemap
@@ -439,76 +368,8 @@ $schedule->command('flexible-content-block-pages:generate-sitemap')
439368
->at('03:00');
440369
```
441370

442-
### Linkable Models
443-
444-
To include your own models in the sitemap, ensure they implement [the `Linkable` contract and have a `getViewUrl()` method](https://github.com/statikbe/laravel-filament-flexible-content-blocks#linkable).
445-
446-
You will most likely already have added those models to the menu configuration's `linkable_models` array or
447-
[call-to-actions models](https://github.com/statikbe/laravel-filament-flexible-content-blocks#linkable) then they will automatically be included in the sitemap.
448-
449-
If you do not want your model in menus or call-to-actions, you can extend the [SitemapGeneratorService](src/Services/SitemapGeneratorService.php).
450-
451-
### Extending the SitemapGeneratorService
452-
453-
For full customization power, you can create your own sitemap generator service by extending the base class or completely
454-
implementing a new service by implementing [GeneratesSitemap](src/Services/Contracts/GeneratesSitemap.php):
455-
456-
```php
457-
<?php
458-
459-
namespace App\Services;
460-
461-
use Statikbe\FilamentFlexibleContentBlockPages\Services\SitemapGeneratorService;
462-
463-
class CustomSitemapGeneratorService extends SitemapGeneratorService
464-
{
465-
protected function addCustomUrls(): void
466-
{
467-
parent::addCustomUrls();
468-
469-
// Add your custom logic
470-
$this->addToSitemap(
471-
url: 'https://example.com/dynamic-page',
472-
lastModifiedAt: now(),
473-
priority: 0.7,
474-
frequency: 'weekly'
475-
);
476-
}
477-
478-
protected function getLinkableModels(): array
479-
{
480-
$models = parent::getLinkableModels();
481-
482-
// Add additional models not in menu/CTA config
483-
$models[] = \App\Models\BlogPost::class;
484-
$models[] = \App\Models\Event::class;
485-
486-
return $models;
487-
}
488-
489-
protected function calculatePriority($page): float
490-
{
491-
// Custom priority logic
492-
if ($page->is_featured) {
493-
return 0.9;
494-
}
495-
496-
return parent::calculatePriority($page);
497-
}
498-
}
499-
```
500-
501-
Then update your configuration to use your custom service:
502-
503-
```php
504-
// config/filament-flexible-content-block-pages.php
505-
'sitemap' => [
506-
'generator_service' => \App\Services\CustomSitemapGeneratorService::class,
507-
// ... other config
508-
],
509-
```
510-
511-
You can override any protected method to customize the sitemap generation behavior, including priority calculation, change frequency, URL filtering, or adding entirely new content types.
371+
For advanced configuration options, generation methods, linkable models setup, and extending the sitemap generator service,
372+
see the [sitemap customisation documentation](documentation/extending-and-customisation.md#sitemap).
512373

513374
## Authorisation
514375

@@ -527,6 +388,8 @@ You can modify the published configuration file to match your application's requ
527388

528389
For detailed configuration options and examples, see the [configuration documentation](documentation/configuration.md).
529390

391+
If you want to further customise or extend the functionality, have a look [at the options](documentation/extending-and-customisation.md).
392+
530393
## TODO's
531394

532395
check:

0 commit comments

Comments
 (0)