定制 lkt/templates 二次开发

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

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

lkt/templates

最新稳定版本:2.0.1

Composer 安装命令:

composer require lkt/templates

包简介

LKT PHP Template

README 文档

README

It's simple. It's fast. It's LKT Templates!

Are you tired of complex PHP template engine?

Would you like to code just like in regular PHP?

Then this lib is for you!

Installation

composer require lkt/templates

Usage

The layout file

LKT Templates works with PHTML/PHP files.

In a PHTML file you can do anything you can do with PHP, just remember the colon syntax.

For example, take this layout.phtml file:

<div><?php echo $title; ?></div>

<?php foreach ($data as $datum): ?>
    <div><?php echo $datum; ?></div>
<?php endforeach; ?>

<?php if(isset($favouriteDrink)): ?>
    <div>Favourite drink: <?php echo $favouriteDrink; ?></div>
<? endif; ?>

You may be asking where the data came from? That's what follows

The Template instance: Access to the layout

This is how you access to layout.phtml:

use Lkt\Templates\Template;

// Create a template instance:
$template = Template::file('layout.phtml'); // You can set a relative path, but absolute path it's allowed too

// Feed the data
$template->setData([
    'title' => 'Hello from LKT Templates!',
    'data' => [1,2]
]);

// If you want to, you can add more data with:
$template->set('favouriteDrink', 'Apple juice'); // PEGI 3+ example

// Parse the layout
$html = $template->parse(); // String returned

// And now you can just print the html or do whatever you want to do with that string
echo $html;

// Alternatively, you can just print the template, and it will be automatically parsed:
echo $template; // equal to echo $template->parse();

The generated HTML

The layout used in this readme feed with data as shown in the PHP example will print something like this:

<div>Hello from LKT Templates!</div>
<div>1</div>
<div>2</div>
<div>Favourite drink: Apple juice</div>

Additional notes

Access a template file with constant path:

$template = Template::file(__DIR__ . '/path/to/layout.phtml');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固