ttek/tk-domtemplate
Composer 安装命令:
composer require ttek/tk-domtemplate
包简介
PHP DomTemplate library
README 文档
README
Project: ttek/tk-domtemplate
Authors: Michael Mifsud http://www.tropotek.com/
Documentation: http://domtemplate.tropotek.com/
Introduction
The PHP \Dom\Template wraps the DOMDocument and provides a fast, attribute-driven way to render HTML templates. We did not want another template language within a language, but a way to use PHP to render HTML templates keeping the render logic within PHP and the style and layout logic in HTML.
An important feature for us was the template layout and design were kept in the HTML so that it could be easily edited by designers and not be affected by what the developers in the team are doing. Making communication between developers and designers relatively easy for most tasks.
The \Dom\Template system enables developers to develop and share a basic markup structure, designers can then see visually and understand what the minimum markup requirements are. Saving on communication time and allowing designers to focus on making the project look great.
Features:
- Mark “variables” and “choices” in your HTML and set their content or visibility
- Manage repeating regions for table row insertion
- Insert/append/replace HTML fragments
- Add CSS/JS (inline or external) and meta/head elements
- Compose pages by merging templates, other DOMDocument's, or HTML strings
Key ideas:
- Use attributes in your HTML to mark nodes:
- var: mark nodes whose content/attributes you’ll set
- choice: mark nodes hidden that you can show in your renderer
- repeat: define repeating regions
- Work with the template (set text/HTML, attributes, headers) before parsing.
- Call
toString()orgetDocument()to parse the template and return a renderable DOMDocument or HTML string.
Installation
Available on Packagist (ttek/tk-domtemplate) and as such installable via Composer.
$ composer require ttek/tk-domtemplate
Or add the following to your composer.json file:
{
"require": {
"ttek/tk-domtemplate": "~8.0"
}
}
Basic Template Usage
<?php ob_start(); ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PHP Dom Template (PDT) Library</title> </head> <body> <div id="content"> <h1>Hello World</h1> <p var="helloWorld">Default Text</p> <p> </p> </div> </body> </html> <?php // Include lib, you should use use composer if available. $basepath = dirname(__FILE__, 3); include_once $basepath . '/vendor/autoload.php'; // Create a template from the html in the buffer $html = trim(ob_get_clean()); $template = \Dom\Template::load($buff); // Add some style $template->appendCssUrl('stylesheet.css'); // Add some javascript $template->appendJs('alert();'); // Set some dynamic text $template->setText('helloWorld', 'This is the `Hello World` Dynamic text.'); echo $template->toString();
Contributing
If you wish to contribute updates to the code or documentation, we are open to any requests.
Use the GitHub discussions area to chat about what you would like to see or contribute.
ttek/tk-domtemplate 适用场景与选型建议
ttek/tk-domtemplate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.93k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2014 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「scss」 「html」 「dom」 「tropotek」 「DomTemplate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ttek/tk-domtemplate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ttek/tk-domtemplate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ttek/tk-domtemplate 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Load DOM document safety
HTML and form generation
Zend Framework 3+ module that provides assets bundling / caching
Added a method to Laravel response for handling xml response and also converting Eloquent return to XML.
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 1.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 21
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-02