You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-17Lines changed: 20 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -2,25 +2,22 @@
2
2
3
3
**Better attribute API for snippets and templates**
4
4
5
-
This plugin brings [Vue.js](https://vuejs.org)/[Laravel-Blade](https://laravel.com/docs/9.x/blade#components)-like attribute composition to the templates of your [Kirby](https://getkirby.com) yproject. This is an exploration in search of better HTML attribute handling for nested snippets and components.
6
-
7
-
**⚠️ Work-in-progress, use at your own risk ⚠️**
8
-
5
+
This plugin brings [Vue.js](https://vuejs.org)/[Laravel-Blade](https://laravel.com/docs/9.x/blade#components)-like attribute composition to the templates of your [Kirby project](https://getkirby.com). This is an exploration in search of better HTML attribute handling for nested snippets and components.
9
6
10
7
## Requirements
11
8
12
-
- Kirby 3.8
9
+
- Kirby 3.8+
13
10
- PHP 8.1 (because of [Enumeration](https://www.php.net/manual/en/language.types.enumerations.php) support)
14
11
15
12
## Installation
16
13
17
-
During this early development stage, installation only works via composer:
Alternatively, if you want to contribute to the development of this plugin, you can install it via submodule or clone this repository and use it as a local composer dependency.
20
+
Alternatively, you can also [download the plugin](https://github.com/fabianmichael/kirby-template-attributes/archive/main.zip) and install it manually by copying it to the `site/plugins/` folder of your website.
24
21
25
22
## Usage
26
23
@@ -37,14 +34,18 @@ Use the `attributes()` helper for generating a string of attributes:
37
34
You can also use named arguments if you prefer a leaner syntax. Be aware, that this only works as long as you don’t have dashes in your attribute names:
38
35
39
36
```php
40
-
<svg <?= attributes(
37
+
<img <?= attributes(
41
38
class:'icon',
42
39
width:16,
43
40
height:16,
44
-
viewBox:'0 0 16 16',
45
-
)?>>[…]</svg>
41
+
src:$image->url(),
42
+
alt: 'The funniest donkey ever!',
43
+
) ?>>
46
44
```
47
45
46
+
⚠️ If you need XML-compatible attributes, always call `$attributes->toXml()` instead of just echoing the `Attributes` object,
47
+
because otherwise all attributes will be converted to lower-case.
48
+
48
49
In many cases, you need to set different classes. The `classes()` helper is a nice shortcut for improved readability:
49
50
50
51
```php
@@ -88,16 +89,13 @@ The `classes()` helper is pretty flexible and also accepts multiple paramaters,
88
89
]) ?>
89
90
```
90
91
91
-
## Custom merge strategies
92
-
93
-
- Custom merge strategies for arbitrary attributes
94
-
95
-
96
92
## Before/After
97
93
94
+
You can set `$before` and `$after`, just like for Kirby’s `Html::attr()` helper by using the corresponding methods:
95
+
98
96
```
99
-
->before()
100
-
->after()
97
+
attributes(class: 'foo')->before(' ');
98
+
attributes(class: 'foo')->after(' ');
101
99
```
102
100
103
101
## Examples
@@ -164,3 +162,8 @@ This is already cool and makes working with attributes for snippets much easier,
164
162
]) ?>
165
163
</nav>
166
164
```
165
+
166
+
167
+
## License
168
+
169
+
MIT (but you are highly encouraged to **[❤️ sponsor me](https://github.com/sponsors/fabianmichael)**, if this piece of software helps you to pay your bills).
0 commit comments