Skip to content

Commit

Permalink
Fix an issue with Partials::get() and partial names without a slash
Browse files Browse the repository at this point in the history
  • Loading branch information
teppokoivula committed Mar 1, 2022
1 parent b6757da commit 191d2be
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.22.1] - 2022-03-01

### Fixed
- Second argument to Partials::get() wasn't applicable unless partial name had at least one slash; this has now been fixed.

## [0.22.0] - 2022-03-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion Wireframe.info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Wireframe",
"summary": "Wireframe is an output framework for ProcessWire CMS/CMF.",
"version": "0.22.0",
"version": "0.22.1",
"author": "Teppo Koivula",
"href": "https://wireframe-framework.com",
"requires": [
Expand Down
2 changes: 1 addition & 1 deletion Wireframe.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @method static string|Page|NullPage page($source, $args = []) Static getter (factory) method for Pages.
* @method static string|null partial(string $partial_name, array $args = []) Static getter (factory) method for Partials.
*
* @version 0.22.0
* @version 0.22.1
* @author Teppo Koivula <[email protected]>
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/
*/
Expand Down
12 changes: 6 additions & 6 deletions lib/Partials.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public function render(string $key, array $arguments = []): ?string {
*/
public function get($key) {
$partial = null;
if (\is_string($key) && strpos($key, '/')) {
$subkeys = array_filter(explode('/', $key));
if (!empty($subkeys)) {
foreach ($subkeys as $subkey) {
$partial = ($partial ?? $this)->data[$subkey] ?? null;
if (\is_string($key)) {
$names = strpos($key, '/') ? array_filter(explode('/', $key)) : [$key];
if (!empty($names)) {
foreach ($names as $name) {
$partial = ($partial ?? $this)->data[$name] ?? null;
if ($partial === null) break;
}
if (\func_num_args() > 1) {
if ($partial !== null && \func_num_args() > 1) {
$arguments = \func_get_arg(1);
if (\is_array($arguments)) {
return $partial->render($arguments);
Expand Down

0 comments on commit 191d2be

Please sign in to comment.