Skip to content

Commit

Permalink
+ Outputters → Json → Parameters → `outputterParams->templates->noRes…
Browse files Browse the repository at this point in the history
…ults`: The new optional parameter. Allows to specify a chunk or text to output when no items found.
  • Loading branch information
Ronef committed Oct 6, 2024
1 parent ee75c7f commit 853acec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,14 @@ Get resources from custom DB table.
* Valid values:
* `stringChunkName`
* `string` — use inline templates starting with `@CODE:`
* **Required**
* Default value: —

* `outputterParams->templates->noResults`
* Description: A chunk or text to output when no items found.
* Valid values:
* `stringChunkName`
* `string` — use inline templates starting with `@CODE:`
* Default value: `'[]'`


#### Outputter → Sitemap (``&outputter=`sitemap` ``)
Expand Down
22 changes: 17 additions & 5 deletions src/Outputter/Json/Outputter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Outputter extends \ddGetDocuments\Outputter\Outputter {
/**
* parse
* @version 2.5.1 (2024-10-06)
* @version 2.6 (2024-10-06)
*
* @param $data {Output}
*
Expand Down Expand Up @@ -76,9 +76,21 @@ public function parse(Output $data){
$result[] = $result_item;
}

return \DDTools\Tools\Objects::convertType([
'object' => $result,
'type' => 'stringJsonAuto',
]);
if (
empty($result)
&& \DDTools\Tools\Objects::isPropExists([
'object' => $this->templates,
'propName' => 'noResults',
])
){
$result = $this->templates->noResults;
}else{
$result = \DDTools\Tools\Objects::convertType([
'object' => $result,
'type' => 'stringJsonAuto',
]);
}

return $result;
}
}

0 comments on commit 853acec

Please sign in to comment.