Hi,
checking if its possible to have a 'set variable and operations' in the parser / template system.
example:
some_controller
-------------------------
$student_names = $controller1->function1();
// $student_names = array ('a', 'b','c')
$student_points = $controller2->function2();
//$student_gracepoints['a'] = 10
//$student_gracepoints['b'] = 20
//$student_gracepoints['c'] = 30
$student_subjects = $controller3->function3();
//$student_subjects['a'] = array ( 'maths' => 10, 'science => '15' );
//$student_subjects['b'] = array ( 'maths' => 30, 'science => '20' );
//$student_subjects['c'] = array ( 'maths' => 50, 'science => '25' );
$pagedata = array (
'names' => $student_names,
'gracepoints' => $student_gracepoints,
'subjects' => $student_subjects
);
echo $parser->setData($pagedata)->render('some-view');
-------------------------
What I need in the view.
for each student, generate this type of total in the view
a_total = 10 (math) + 15(science) + 10 (gracepoint) = 35
b_total = 30 (math) + 20(science) + 20 (gracepoint) = 70
c_total = 50 (math) + 25(science) + 30 (gracepoint) = 105
Simple example here, but the idea is it will allow to create dynamic charts and data in the view without having to run a for-each loop in the controller itself on each array ( as those again needed to be done in the view page anyway ) for rendering those on different parts of the page.
One way is to run all those in the controller and create one big array , send that big array to the page and then display only what is necessary.
Another method might be if its possible to have like a {set name.total == 0 } kind of twig feature to allow to create a variable in the view itself, and then populating that while the view is being constructed.
This way, the controller can be kept sane, and some logic can be passed to the template itself.