Skip to content

Commit 29f9923

Browse files
committed
ComponentRenderer used on all components
1 parent dc8b95b commit 29f9923

File tree

14 files changed

+284
-307
lines changed

14 files changed

+284
-307
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.2.0] - 2025-03-20
9+
### Changes
10+
- Usage of the `ComponentRenderer` trait on all components
11+
- Composer requires `NumenCode.Fundamentals` version 1.1 or higher
12+
813
## [1.1.0] - 2025-03-06
914
### Added
1015
- Gallery - manage multiple image galleries

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ php artisan winter:up
3535

3636
## Requirements
3737

38-
* [NumenCode Fundamentals Plugin](https://github.com/numencode/wn-fundamentals-plugin) version ^1.0 or higher.
38+
* [NumenCode Fundamentals Plugin](https://github.com/numencode/wn-fundamentals-plugin) version ^1.1 or higher.
3939
* [Winter CMS](https://wintercms.com/) 1.2.7 or higher.
4040
* PHP version 8.0 or higher.
4141

@@ -47,6 +47,22 @@ This plugin provides an intuitive interface to create and manage a variety of wi
4747
to customize their websites with ease. With multilingual support via the `Winter.Translate` plugin,
4848
it ensures global usability.
4949

50+
### Component Rendering System
51+
52+
All widget components in this plugin leverage the `ComponentRenderer` trait from the **NumenCode.Fundamentals** plugin.
53+
This provides several key benefits:
54+
55+
- **Automatic Alias Resolution**: Each component’s alias is automatically set based on its class name.
56+
- **Customizable Rendering**: Users can override default component templates via theme partials.
57+
- **Layout Selection**: Components support multiple layout options, allowing greater flexibility in presentation.
58+
59+
To override a component’s layout, create a folder inside your theme's partials directory matching the component's alias
60+
(e.g., `/themes/custom/partials/mycomponent`) and add layout files like `default.htm`, `special.htm`, etc.
61+
62+
---
63+
64+
## Available Widgets
65+
5066
### Counters
5167

5268
Showcase statistics or numeric information on your website using dynamic and engaging animated counters.

components/Counters.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php namespace NumenCode\Widgets\Components;
22

33
use Cms\Classes\ComponentBase;
4+
use NumenCode\Fundamentals\Traits\ComponentRenderer;
45

56
class Counters extends ComponentBase
67
{
8+
use ComponentRenderer;
9+
710
public $counters;
811

912
public function componentDetails(): array

components/Features.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
use Cms\Classes\ComponentBase;
44
use NumenCode\Widgets\Models\FeatureGroup;
5+
use NumenCode\Fundamentals\Traits\ComponentRenderer;
56

67
class Features extends ComponentBase
78
{
9+
use ComponentRenderer;
10+
811
public $group;
912

1013
public function componentDetails(): array
@@ -38,28 +41,11 @@ public function onRun()
3841
$this->group = $this->loadGroup();
3942
}
4043

41-
public function onRender()
42-
{
43-
if (!$layout = $this->property('layout')) {
44-
$layout = 'default';
45-
}
46-
47-
return $this->renderPartial('@' . $layout . '.htm');
48-
}
49-
5044
public function getTitleOptions(): array
5145
{
5246
return FeatureGroup::lists('title', 'id');
5347
}
5448

55-
public function getLayoutOptions(): array
56-
{
57-
return [
58-
'default' => 'Default',
59-
'media' => 'Default with pictures',
60-
];
61-
}
62-
6349
protected function loadGroup()
6450
{
6551
return FeatureGroup::find($this->property('title'));

components/Gallery.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
use Cms\Classes\ComponentBase;
44
use NumenCode\Widgets\Models\GalleryGroup;
5+
use NumenCode\Fundamentals\Traits\ComponentRenderer;
56

67
class Gallery extends ComponentBase
78
{
9+
use ComponentRenderer;
10+
811
public $gallery;
912
public $itemsPerRow;
1013

@@ -47,27 +50,11 @@ public function onRun()
4750
$this->itemsPerRow = $this->property('items_per_row') ?? 4;
4851
}
4952

50-
public function onRender()
51-
{
52-
if (!$layout = $this->property('layout')) {
53-
$layout = 'default';
54-
}
55-
56-
return $this->renderPartial('@' . $layout . '.htm');
57-
}
58-
5953
public function getTitleOptions(): array
6054
{
6155
return GalleryGroup::lists('title', 'id');
6256
}
6357

64-
public function getLayoutOptions(): array
65-
{
66-
return [
67-
'default' => 'Default',
68-
];
69-
}
70-
7158
protected function loadGallery()
7259
{
7360
return GalleryGroup::find($this->property('title'));

components/Highlights.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
use Cms\Classes\ComponentBase;
44
use NumenCode\Widgets\Models\HighlightGroup;
5+
use NumenCode\Fundamentals\Traits\ComponentRenderer;
56

67
class Highlights extends ComponentBase
78
{
9+
use ComponentRenderer;
10+
811
public $group;
912

1013
public function componentDetails(): array
@@ -38,27 +41,11 @@ public function onRun()
3841
$this->group = $this->loadGroup();
3942
}
4043

41-
public function onRender()
42-
{
43-
if (!$layout = $this->property('layout')) {
44-
$layout = 'default';
45-
}
46-
47-
return $this->renderPartial('@' . $layout . '.htm');
48-
}
49-
5044
public function getTitleOptions(): array
5145
{
5246
return HighlightGroup::lists('title', 'id');
5347
}
5448

55-
public function getLayoutOptions(): array
56-
{
57-
return [
58-
'default' => 'Default',
59-
];
60-
}
61-
6249
protected function loadGroup()
6350
{
6451
return HighlightGroup::find($this->property('title'));

components/Promotions.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
use Cms\Classes\ComponentBase;
44
use NumenCode\Widgets\Models\PromotionGroup;
5+
use NumenCode\Fundamentals\Traits\ComponentRenderer;
56

67
class Promotions extends ComponentBase
78
{
9+
use ComponentRenderer;
10+
811
public $group;
912

1013
public function componentDetails(): array
@@ -38,27 +41,11 @@ public function onRun()
3841
$this->group = $this->loadGroup();
3942
}
4043

41-
public function onRender()
42-
{
43-
if (!$layout = $this->property('layout')) {
44-
$layout = 'default';
45-
}
46-
47-
return $this->renderPartial('@' . $layout . '.htm');
48-
}
49-
5044
public function getTitleOptions(): array
5145
{
5246
return PromotionGroup::lists('title', 'id');
5347
}
5448

55-
public function getLayoutOptions(): array
56-
{
57-
return [
58-
'default' => 'Bootstrap 4',
59-
];
60-
}
61-
6249
protected function loadGroup()
6350
{
6451
return PromotionGroup::find($this->property('title'));
File renamed without changes.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"php": "^8.0.2",
22-
"numencode/wn-fundamentals-plugin": "^1.0"
22+
"numencode/wn-fundamentals-plugin": "^1.1"
2323
},
2424
"extra": {
2525
"installer-name": "widgets"

0 commit comments

Comments
 (0)