> 如果系統自帶的解析規則不能滿足需求, 可以使用 Angular::extend()方法進行擴展, 此方法有兩個參數, 詳細請看下面實例.
## 入口文件: /test/index.php
```
<?php
use think\angular\Angular;
require '../src/Angular.php';
// 自定義擴展, 打印變量的值
Angular::extend('dump', function ($content, $param, $angular) {
$old = $param['html'];
$new = '<pre>';
unset($param[0], $param[1], $param[2], $param[3], $param[4], $param[5]);
$new .= '<?php var_dump(' . $param['value'] . '); ?>';
$new .= '<pre>';
return str_replace($old, $new, $content);
});
// 自定義擴展, 變量+1
Angular::extend('inc', function ($content, $param, $angular) {
$old = $param['html'];
$new = '<?php ' . $param['value'] . '++; ?>';
$new .= Angular::removeExp($old, $param['exp']);
return str_replace($old, $new, $content);
});
// 自定義擴展, 變量-1
Angular::extend('dec', function ($content, $param, $angular) {
$old = $param['html'];
$new = '<?php ' . $param['value'] . '--; ?>';
$new .= Angular::removeExp($old, $param['exp']);
return str_replace($old, $new, $content);
});
/ 配置
$config = [
'debug' => true, // 是否開啟調試, 開啟調試會實時生成緩存
'tpl_path' => './view/', // 模板根目錄
'tpl_suffix' => '.html', // 模板后綴
'tpl_cache_path' => './cache/', // 模板緩存目錄
'tpl_cache_suffix' => '.php', // 模板緩存后綴
'directive_prefix' => 'php-', // 指令前綴
'directive_max' => 10000, // 指令的最大解析次數
];
// 實例化
$view = new Angular($config);
// 輸出解析結果
$view->display('index');
```
## 模板文件: /text/view/index.html
```
<!DOCTYPE html>
<html>
<head>
<title>diy test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div php-dump="$navs"></div>
<div php-init="$i = 0" php-inc="$i" php-inc="$i">{$i}</div>
<div php-dec="$i">{$i}</div>
</body>
</html>
```
## 解析后
```
<!DOCTYPE html>
<html>
<head>
<title>diy test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<pre><?php var_dump($navs); ?><pre>
<?php $i = 0; $i++; $i++; ?>
<div><?php echo $i; ?></div>
<?php $i--; ?>
<div><?php echo $i; ?></div>
</body>
</html>
```