PHP Looping Template Engine - From Scratch

后端 未结 6 1406
鱼传尺愫
鱼传尺愫 2020-12-24 04:46

For a group project I am trying to create a template engine for PHP for the people less experienced with the language can use tags like {name} in their HTML and the PHP will

6条回答
  •  半阙折子戏
    2020-12-24 05:11

    If I'm not worried about caching or other advanced topics that would push me to an established template engine like smarty, I find that PHP itself is a great template engine. Just set variables in a script like normal and then include your template file

    $name = 'Eric';
    $locations = array('Germany', 'Panama', 'China');
    
    include('templates/main.template.php');
    

    main.tempate.php uses an alternative php tag syntax that is pretty easy for non php people to use, just tell them to ignore anything wrapped in a php tag :)

    Your name is

    ... page continues ...

提交回复
热议问题