-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.php
32 lines (28 loc) · 862 Bytes
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
use FabianMichael\TemplateAttributes\Attributes;
use Kirby\Toolkit\A;
/**
* Generates an attribuets object for further manipulation or echoing as string
*
* @param array|Attributes $data A list of attributes as key/value array, an instance of \FabianMichael\TemplateAttributes\Attributes (useful for nested snippets) or a list of named arguments
* @return \FabianMichael\TemplateAttributes\Attributes
*/
function attributes(...$args): Attributes
{
return new Attributes(...$args);
}
/**
* Shortcut for creating an attributes object andsetting the class attribute.
*
* @return \FabianMichael\TemplateAttributes\Attributes
*/
function classes(...$classes): Attributes
{
// flatten array inputs
$classes = array_reduce(
$classes,
fn ($carry, $item) => array_merge($carry, A::wrap($item)),
[]
);
return attributes()->class($classes);
}