Skip to content

Commit 6120d0b

Browse files
committed
Support array of atom paths
1 parent c854626 commit 6120d0b

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.5 - 2023-06-08
2+
### Changed
3+
- `atoms` config option now supports an array of paths
4+
15
## 1.0.4 - 2020-02-15
26
### Fixed
37
- Fix error when using nested atom name (`/`) in closing tag

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ether/atom",
33
"description": "Adding enhanced modularity to Craft CMS Twig templating",
4-
"version": "1.0.4",
4+
"version": "1.0.5",
55
"type": "craft-plugin",
66
"license": "MIT",
77
"minimum-stability": "dev",

src/Atom.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,25 @@ public static function renderAtom (
5353
) : void {
5454
$view = Craft::$app->getView();
5555

56-
$template = self::$_config['atoms'] . '/' . $handle;
56+
$atomPaths = self::$_config['atoms'];
57+
if (!is_array($atomPaths)) $atomPaths = [$atomPaths];
5758

5859
$variables['children'] = new Markup($children, 'utf8');
5960

60-
if (!$view->doesTemplateExist($template))
61+
foreach ($atomPaths as $path)
6162
{
62-
Craft::error(
63-
"Error locating template: {$template}",
64-
__METHOD__
65-
);
63+
$template = $path . '/' . $handle;
6664

67-
return;
65+
if ($view->doesTemplateExist($template)) {
66+
echo $view->renderTemplate($template, $variables);
67+
return;
68+
}
6869
}
6970

70-
echo $view->renderTemplate($template, $variables);
71+
Craft::error(
72+
"Error locating template: {$handle}",
73+
__METHOD__
74+
);
7175
}
7276

7377
}

src/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* _Defaults to `_atoms`_
88
*
99
* The location of your atoms, relative to your `templates` directory.
10+
* Can also be an array of paths, in descending order of priority.
1011
*/
1112
'atoms' => '_atoms',
1213
];

0 commit comments

Comments
 (0)