Skip to content

Commit 29f2946

Browse files
committed
chore: update README
1 parent df074e6 commit 29f2946

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
Kirby Helpers is a collection of useful helper functions for Kirby CMS.
44

5+
## Features
6+
7+
- 🎨 **CSS Helpers** - Lazy loading, conditional loading by template or block type
8+
- 🔗 **Link Helpers** - Automatic link labels, external link detection, mailto builders
9+
- 📝 **String Helpers** - Prefix/suffix utilities for consistent formatting
10+
- 🌐 **Translation Helpers** - Translation status checking, filtering, and badges
11+
- ♿️ **Accessibility** - SVG accessibility attributes, automatic link titles
12+
- 🎯 **Block Helpers** - Extract and analyze block types for conditional styling
13+
- ⚡️ **Vite Integration** - Dev mode detection, asset inlining
14+
- 🏗️ **HTML Utilities** - Heading level validation and manipulation
15+
516
## Installation via Composer
617
To install Kirby Helpers via Composer, run the following command:
718

@@ -25,6 +36,7 @@ cssLazy(vite()->asset('styles/carousel.scss'), true);
2536
Load CSS only if a specific block type is used on the page.
2637

2738
```php
39+
$pageBlocks = getUsedBlockTypes($page->text()->toBlocks());
2840
cssIfBlock('assets/css/carousel.css', 'carousel', $pageBlocks);
2941
cssIfBlock(vite()->asset('styles/carousel.scss'), 'carousel', $pageBlocks, true);
3042
```
@@ -96,6 +108,21 @@ validateHeadingLevel('h7'); // Throws InvalidArgumentException
96108

97109
---
98110

111+
### Block Helpers
112+
113+
#### `getUsedBlockTypes(Blocks|array $blocks): array`
114+
Extract all used block types from a Blocks object or array. Useful for conditional CSS loading.
115+
116+
```php
117+
$pageBlocks = getUsedBlockTypes($page->text()->toBlocks());
118+
// ['heading', 'text', 'image', 'gallery']
119+
120+
// Use with cssIfBlock
121+
cssIfBlock('assets/css/gallery.css', 'gallery', $pageBlocks);
122+
```
123+
124+
---
125+
99126
### Link Helpers
100127

101128
#### `setBlankIfExternal(string $link, bool $dontReturnHref = false): array`
@@ -194,13 +221,29 @@ inlineViteAsset(['app.js', 'vendor.js'], 'script');
194221
## Field Methods
195222

196223
### `ensureLeft(string $prefix): string`
224+
Ensure a field value starts with a specific prefix. Returns the field for chaining.
197225
```php
198-
$page->myField()->ensureLeft('https://');
226+
$page->url()->ensureLeft('https://')->value();
199227
```
200228

201229
### `ensureRight(string $suffix): string`
230+
Ensure a field value ends with a specific suffix. Returns the field for chaining.
231+
```php
232+
$page->path()->ensureRight('/')->value();
233+
```
234+
235+
### `ensureHashed(): string`
236+
Ensure a field value starts with a hash character (#). Useful for anchor links. Returns the field for chaining.
237+
```php
238+
$page->anchor()->ensureHashed()->value();
239+
// 'section-1' becomes '#section-1'
240+
```
241+
242+
### `autoLinkTitles(): string`
243+
Automatically add accessible title attributes to all links in HTML content. Detects internal pages, files, email, phone, and external links. Returns the field for chaining.
202244
```php
203-
$page->myField()->ensureRight('/');
245+
$page->text()->kirbytext()->autoLinkTitles();
246+
// Adds appropriate title attributes to all <a> tags
204247
```
205248

206249
---

0 commit comments

Comments
 (0)