Skip to content

Commit

Permalink
Support array of atom paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Jun 8, 2023
1 parent c854626 commit 6120d0b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.5 - 2023-06-08
### Changed
- `atoms` config option now supports an array of paths

## 1.0.4 - 2020-02-15
### Fixed
- Fix error when using nested atom name (`/`) in closing tag
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ether/atom",
"description": "Adding enhanced modularity to Craft CMS Twig templating",
"version": "1.0.4",
"version": "1.0.5",
"type": "craft-plugin",
"license": "MIT",
"minimum-stability": "dev",
Expand Down
20 changes: 12 additions & 8 deletions src/Atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,25 @@ public static function renderAtom (
) : void {
$view = Craft::$app->getView();

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

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

if (!$view->doesTemplateExist($template))
foreach ($atomPaths as $path)
{
Craft::error(
"Error locating template: {$template}",
__METHOD__
);
$template = $path . '/' . $handle;

return;
if ($view->doesTemplateExist($template)) {
echo $view->renderTemplate($template, $variables);
return;
}
}

echo $view->renderTemplate($template, $variables);
Craft::error(
"Error locating template: {$handle}",
__METHOD__
);
}

}
1 change: 1 addition & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* _Defaults to `_atoms`_
*
* The location of your atoms, relative to your `templates` directory.
* Can also be an array of paths, in descending order of priority.
*/
'atoms' => '_atoms',
];

0 comments on commit 6120d0b

Please sign in to comment.