Skip to content

Commit 141f5c8

Browse files
committed
Add spacing config global variable
1 parent d411980 commit 141f5c8

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Release Notes for Spacing
22

3-
## 1.0.0
3+
## 1.0.1 - 2023-04-26
4+
- Setup a `{{ craft.spacing.config }}` to globally access config values in Twig templates
5+
6+
## 1.0.0 - 2023-04-25
47
- Initial release

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "trendyminds/craft-spacing",
33
"description": "A utility field to insert spacing between your Matrix blocks",
44
"type": "craft-plugin",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"license": "mit",
77
"support": {
88
"email": "dev@trendyminds.com",
@@ -36,5 +36,8 @@
3636
"yiisoft/yii2-composer": true,
3737
"craftcms/plugin-installer": true
3838
}
39+
},
40+
"require-dev": {
41+
"laravel/pint": "^1.5"
3942
}
4043
}

src/Spacing.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
use craft\events\RegisterComponentTypesEvent;
88
use craft\helpers\Json;
99
use craft\services\Fields;
10+
use craft\web\twig\variables\CraftVariable;
1011
use Exception;
1112
use Illuminate\Support\Collection;
1213
use trendyminds\spacing\fields\Field;
14+
use trendyminds\spacing\variables\Variable;
1315
use yii\base\Event;
1416

1517
/**
@@ -46,6 +48,16 @@ function (RegisterComponentTypesEvent $event) {
4648
$event->types[] = Field::class;
4749
}
4850
);
51+
52+
Event::on(
53+
CraftVariable::class,
54+
CraftVariable::EVENT_INIT,
55+
function (Event $event) {
56+
/** @var CraftVariable $variable */
57+
$variable = $event->sender;
58+
$variable->set('spacing', Variable::class);
59+
}
60+
);
4961
}
5062

5163
public static function options(): Collection

src/variables/Variable.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace trendyminds\spacing\variables;
4+
5+
use Illuminate\Support\Collection;
6+
use trendyminds\spacing\Spacing;
7+
8+
class Variable
9+
{
10+
public function config(): Collection
11+
{
12+
return Spacing::options();
13+
}
14+
}

0 commit comments

Comments
 (0)