forms - output array to template -
i'm trying add custom form series of radio buttons. need output list template can loop over. when run code nothing gets output. if add text inside loop it's output once.
in page_controller class
public function outputarray($array){ $dl = datalist::create("dataobject"); foreach ($array $it) { $do = new dataobject(); $do->value = $it; $do->write(); $dl->push($do); } return $dl; } public function numlist(){return $this->outputarray(array("0","1","2","3","4","5"));}
in template
<% loop numlist() %> $value <% end_loop %>
you there. how write it:
public function outputarray($array) { $dl = new arraylist(); foreach ($array $it) { $dl->add(array('value' => $it)); } return $dl; }
and in silverstripe template:
<% loop $numlist %> $value <% end_loop %>
if use form class of silverstripe should have @ this: http://api.silverstripe.org/3.1/class-selectiongroup.html enable set key->value array on object , radio buttons rendered silverstripe.
Comments
Post a Comment