定制 sugiphp/ste 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sugiphp/ste

Composer 安装命令:

composer require sugiphp/ste

包简介

Template Engine

关键字:

README 文档

README

Build Status

STE stands for Sugi (or Simple) Template Engine. It is intended to be secure, lightweight and fast.

Unlike some of the famous template engines (like Smarty, Twig, etc.) the template code is not converted (compiled) to PHP code and then evaluated, but parsed on the fly. Variables and blocks are replaced with regular expressions (preg_replace function). This approach has several benefits (and drawbacks). The STE code is light (currently only one file), it is fast (compared to PHP convert-ions), but most of all it is secure - you can give anyone to make a HTML template for your project and it is safe to use since no PHP code can be injected in a template files. And here comes the cons using this approach - all the logic should be done in the PHP code and then passed to the template engine. STE does not recognize even simplest if-then-else statements.

Usage

Template file: index.html

<!DOCTYPE html>
<html>
<head>
	<title>{title}</title>
</head>
<body>
	<ul id="navigation">
		<!-- BEGIN navi -->
		<li><a href="{navi.link}">{navi.title}</a></li>
		<!-- END navi -->
	</ul>
</body>
</html>

PHP file:

<?php

use SugiPHP\STE\Ste;

$tpl = new Ste();
// Load a file
$tpl->load(__DIR__"/index.html");
// or set a raw template from PHP $tpl->setTemplate($htmlTemplate);
// set a variable title
$tpl->assign("title", "My Site");
// sets several links at once - perfect for database results
$tpl->assign("navi", array(
	array("link" => "/blog", "title" => "My Blog"),
	array("link" => "http://gamegix.com", "title" => "Online games")
));
// parse the template
echo $tpl->parse();
?>

The output will be something like this:

<!DOCTYPE html>
<html>
<head>
	<title>My Site</title>
</head>
<body>
	<ul id="navigation">
		<li><a href="/blog">My Blog</a></li>
		<li><a href="http://gamegix.com">Online games</a></li>
	</ul>
</body>
</html>

统计信息

  • 总下载量: 279
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-08-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固