PHP Template engine : Mun Template

2019-08-21   |   by munsiwoo

예전에 PHP로 만든 MVC프레임워크의 렌더링 부분이 많이 지저분해서 최적화하려고 작은 템플릿 엔진을 만들어보았다.
말 그대로 작은 템플릿 엔진이기에 조건문과 반복문, 변수 출력, 변수 전달 이렇게 최소한의 기능만 구현했으며
기존에 있는 Smarty나 Twig같은 엔진을 사용하지 않고 직접 구현한 이유는…

그냥 예전부터 만들어보고 싶었다.
https://github.com/munsiwoo/mun-template


Preview

<!DOCTYPE html>
<html>
<head>
    <title>Mun Template</title>
</head>
<body>
    <h1>Mun Template</h1>
    <p>Mun Template is Simple PHP Template engine.</p>
    <h3>for statement</h3>
    @mun for($i=0; $i<10; $i++)
        @mun for($j=0; $j<$i; $j++)
            *
        @endfor
        <br>
    @endfor
    <hr>
    <h3>if statement and print variable</h3>
    @mun if(!isset($_GET[0]))
        plz input $_GET[0]
    @mun elif($_GET[0] == "munsiwoo")
        hello, admin!
    @mun else
        your input is "@var($_GET[0])"
    @endif

    <hr>
    <h3>print passed variable</h3>
    hello, @var($name)
</body>
</html>

muntemplate


MunTemplate README.md

Simple PHP Template engine
Made by munsiwoo


  • How to use?
<?php
include 'MunTemplate.class.php'; # first include class

$MunTemplate = new MunTemplate('./templates/'); # set path

$my_name = 'munsiwoo';
$MunTemplate->render_template('main.html', ['name'=>$my_name]);

Statements

  • How to use for statement?
@mun for($num=0; $num<10; $num++)
    num is @var($num+1)<br>
@endfor
  • How to use if statement?
@mun if(true)
    <h1>TRUE</h1>
@mun else
    <h1>FALSE</h1>
@endif
  • How to use variable?
<p>your name is @var($name)</p>
  • How to pass variable?
<?php
/* index.php */
render_template('main.html', ['var1'=>'1', 'var2'=>array(1,2,3)]);
<!-- main.html -->
var1 is @var($var1)<br>
var2 is @var($var2)

About Post Author

munsiwoo

CTFer, Web hacking researcher

Leave Your Comment