public renderEach ( string $viewTemplate, array $data, string $eachItemName, string $empty = 'raw|' ) : string | ||
$viewTemplate | string | The view template to use for each subitem, format componentPart://componentName/viewName/layoutName |
$data | array | The array of data you want to render. It can be a DataModel\Collection, array, ... |
$eachItemName | string | How to call each item in the loaded subtemplate (passed through $forceParams) |
$empty | string | What to display if the array is empty |
Résultat | string |
public function renderEach($viewTemplate, $data, $eachItemName, $empty = 'raw|')
{
$result = '';
// If is actually data in the array, we will loop through the data and append
// an instance of the partial view to the final result HTML passing in the
// iterated value of this data array, allowing the views to access them.
if (count($data) > 0) {
foreach ($data as $key => $value) {
$data = array('key' => $key, $eachItemName => $value);
$result .= $this->loadAnyTemplate($viewTemplate, $data);
}
} else {
if (starts_with($empty, 'raw|')) {
$result = substr($empty, 4);
} else {
$result = $this->loadAnyTemplate($empty);
}
}
return $result;
}