File modules/template_engine/components/html/component_list/ListComponent.class.php

Last commit: Tue Oct 13 14:55:30 2026 +0200	Jan Dankert	The XSD Generator is now able to generate XSD annotations (mean: comments), this makes editing the templates much easier :)
1 <?php 2 3 namespace template_engine\components\html\component_list; 4 5 use template_engine\components\html\Component; 6 use template_engine\components\XsdComment; 7 use template_engine\element\PHPBlockElement; 8 9 #[XsdComment("list")] 10 class ListComponent extends Component 11 { 12 13 #[XsdComment("list of elements to iterate over")] 14 public $list; 15 16 #[XsdComment("comma-seperated string of elements to iterate over")] 17 public $items; 18 19 #[XsdComment("boolean switch if the value should be extracted. The value must be an object or associative array")] 20 public $extract = false; 21 22 #[XsdComment("the variable name of the key, default is 'list_key'")] 23 public $key = 'list_key'; 24 25 #[XsdComment("the variable name of the value, default is 'list_value'")] 26 public $value = 'list_value'; 27 28 public function createElement() 29 { 30 $list = new PHPBlockElement(); 31 32 if ( $this->items ) 33 $listValue = '['.implode(',',array_map( function($value){return "'".$value."'";},explode(',',$this->items))).']'; 34 else 35 $listValue = $list->value($this->list); 36 37 $list->beforeBlock = 'foreach((array)'.'@'.$listValue.' as $' . $this->key . '=>$' . $this->value . ')'; 38 39 if ($this->extract) 40 $list->inBlock = 'extract($' . $this->value . ');'; 41 42 return $list; 43 } 44 45 }
Download modules/template_engine/components/html/component_list/ListComponent.class.php
History Tue, 13 Oct 2026 14:55:30 +0200 Jan Dankert The XSD Generator is now able to generate XSD annotations (mean: comments), this makes editing the templates much easier :) Thu, 4 Mar 2021 02:00:11 +0100 Jan Dankert New: Show all page filenames in info. Mon, 8 Feb 2021 23:04:22 +0100 Jan Dankert New: A sidebar with sticky buttons as a shortcut to some methods. Wed, 14 Oct 2020 22:36:29 +0200 Jan Dankert Refactoring: Fixed the namespace in component classes, now the are able to be load by the standard autoloader. Wed, 14 Oct 2020 22:20:22 +0200 Jan Dankert Refactoring: Renamed component folders, because 'if' is no valid namespace fragment.