在一个PHP文件中加载多个模板TWIG


Load multiple templates TWIG in one PHP file

我在用纯PHP编写的项目中安装了TWIG,我想创建一个数组来加载许多*.twig页面或使用$_GET['page']

有可能吗?

这是我的代码:

<?php
    include('twig.php');
    $template = $twig->loadTemplate('testmacro.twig');
    echo $template->render(array()); 
?>

此代码仅加载一个*.twig页面

提前感谢

我认为您只需加载2个模板并调用两次echo函数:

<?php
    include('twig.php');
    $template = $twig->loadTemplate('testmacro.twig');
    echo $template->render(array()); 
    $template2 = $twig->loadTemplate('testmacro2.twig');
    echo $template2->render(array()); 
?>