Skip to content

Commit

Permalink
+ Outputters → Json → Parameters → `outputterParams->templates->wrapp…
Browse files Browse the repository at this point in the history
…er`: The new optional parameter. Allows to specify a wrapper template.
  • Loading branch information
Ronef committed Oct 6, 2024
1 parent 853acec commit 8aa2faf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ Get resources from custom DB table.
* `stringChunkName`
* `string` — use inline templates starting with `@CODE:`
* Default value: `'[]'`

* `outputterParams->templates->wrapper`
* Description: Wrapper template.
* Available placeholders:
* `[+ddGetDocuments_items+]`
* `[+total+]` — number of returned items
* `[+totalFound+]` — number of found items
* Valid values:
* `stringChunkName`
* `string` — use inline templates starting with `@CODE:`
* Default value: `'[+ddGetDocuments_items+]'`


#### Outputter → Sitemap (``&outputter=`sitemap` ``)
Expand Down
18 changes: 17 additions & 1 deletion 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.6 (2024-10-06)
* @version 2.7 (2024-10-06)
*
* @param $data {Output}
*
Expand Down Expand Up @@ -89,6 +89,22 @@ public function parse(Output $data){
'object' => $result,
'type' => 'stringJsonAuto',
]);

if (
\DDTools\Tools\Objects::isPropExists([
'object' => $this->templates,
'propName' => 'wrapper',
])
){
$result = \ddTools::parseText([
'text' => $this->templates->wrapper,
'data' => [
'ddGetDocuments_items' => $result,
'total' => count($data->provider->items),
'totalFound' => $data->provider->totalFound,
],
]);
}
}

return $result;
Expand Down

0 comments on commit 8aa2faf

Please sign in to comment.