简体   繁体   中英

Render twig template more than once

How do I render variables "as I go", rather than in one go? In other words, what's the correct way to do this:

$template=$twig->loadTemplate('/theme/index.html');
..figure out $score
$template->render(array("score"=>$score));
..figure out $user
echo $template->render(array("user"=>$user));

Just build options array as you go, and then pass it to template in the end.

$options = array();
//figure out $score
$options['score'] = $score
//figure out $user
$options['user'] = $user;

//render
echo $template->render($options);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM