[英]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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.