kovsky0 / mini-templater
一个简单的辅助类,用于处理变量和替代字符串
dev-master
2017-11-27 12:41 UTC
This package is not auto-updated.
Last update: 2024-09-23 07:17:50 UTC
README
一个简单的辅助类,用于处理变量和替代字符串。基于Jason Davis的Spintax。
安装
通过Composer安装
composer require kovsky0/mini-templater
入门
要开始,您需要引入mini-templater.php
<?php require_once('vendor/autoload.php');
如何使用它
处理替代字符串
<?php $templater = new MiniTemplater; $example = "This is an {{example.|exemplary usage of the class.}}"; echo $templater->process($example);
递归处理替代字符串
<?php $templater = new MiniTemplater; $example = "This is an {{example.|exemplary usage of {{the|my}} class.}}"; echo $templater->process($example);
处理变量
<?php $templater = new MiniTemplater; $example = "This is an [[example_text]]"; $variables = array("example_text" => "exemplary usage of the class."); echo $templater->process($example, $variables);
变量内的替代字符串处理
<?php $templater = new MiniTemplater; $example = "This is an [[example_text]]"; $variables = array("example_text" => "{{example.|exemplary usage of the class.}}"); echo $templater->process($example, $variables);