Change template engine of thinkphp(3.2.3) to twig

Create new Twig.class.php in Thinkphp/Library/Think/Template/Driver/

 CACHE_PATH,
            'auto_reload' => true,
            'debug' => true,// 开启debug
        ]);
        
        $twig->addExtension(new \Twig_Extension_Debug());// 开启debug
        $twig->addFunction(new \Twig_SimpleFunction('session', 'session'));// 映射系统函数session
        $twig->addFunction(new \Twig_SimpleFunction('I', 'I'));// 映射系统函数I

        $templateFile = substr($templateFile,strlen(THEME_PATH));
        echo $twig->render($templateFile, $var);
    }
}

Change config

 'Twig',
    'TMPL_TEMPLATE_SUFFIX' => '.twig',
];

or

// set before call ($this->display()) on the fly
C('TMPL_ENGINE_TYPE', 'Twig');
C('TMPL_TEMPLATE_SUFFIX', '.twig');

你可能感兴趣的:(php,thinkphp,template-engine,twig)