phalette/platte
最新稳定版本:0.2
Composer 安装命令:
composer require phalette/platte
包简介
Nette Latte template adapter for Phalcon
README 文档
README
Website 🚀 contributte.org | Contact 👨🏻💻 f3l1x.io | Twitter 🐦 @contributte
Disclaimer
| ⚠️ | This project is no longer being maintained. |
|---|
| Composer | phalette/platte |
|---|---|
| Version | |
| PHP | |
| License |
About
Combination of one of the best template engine Latte and pretty fast framework Phalcon.
Install
$ composer require phalette/platte:dev-master
Dependencies
- PHP >= 5.5.0
- Latte >= 2.3.0
- Phalcon >= 2.0.0
Configuration
Register Platte as your next template engine.
use Phalette\Platte\Latte\LatteFactory; use Phalette\Platte\LatteTemplateAdapter; $di->set('view', function () { $view = new View(); $view->registerEngines([ ".latte" => function ($view, $di) { $factory = new LatteFactory(); $factory->setTempDir(__DIR__ . '/cache'); return new LatteTemplateAdapter($view, $di, $factory); }, ]); return $view; });
Features from Phalcon
You can access variables in templates.
| Variables | |
|---|---|
$_view |
Phalcon\Mvc\View |
$_tag |
Phalcon\Tag |
$_url |
Phalcon\Mvc\Url |
$_security |
Phalcon\Security |
In extreme cases you can access $_di. But I really not recommend it.
Macros
| Files & contents | |
|---|---|
{content} |
$_view->getContent() |
{partial} |
$_view->getPartial($path) |
| Links & urls | |
|---|---|
{linkTo} |
$_tag->linkTo($args...) |
{url} |
$_url->get($uri) |
| Forms | |
|---|---|
{textField} |
$_tag->textField($args) |
{passwordField} |
$_tag->passwordField($args) |
{hiddenField} |
$_tag->hiddenField($args) |
{fileField} |
$_tag->fileField($args) |
{radioField} |
$_tag->radioField($args) |
{submitButton} |
$_tag->submitButton($args) |
{selectStatic} |
$_tag->selectStatic($args...) |
{select} |
$_tag->select($args...) |
{textArea} |
$_tag->textArea($args) |
{form} |
$_tag->form($args) |
{endForm} |
$_tag->endForm() |
| Other | |
|---|---|
{title} |
$_tag->getTitle() |
{friendlyTitle} |
$_tag->friendlyTitle($args...) |
{doctype} |
$_tag->getDocType() |
| Assets | |
|---|---|
{stylesheetLink} |
$_tag->stylesheetLink($args...) |
{css} |
$_tag->javascriptInclude($args...) |
{javascriptInclude} |
$_tag->javascriptInclude($args...) |
{js} |
$_tag->javascriptInclude($args...) |
{image} |
$_tag->image($args) |
| Security | |
|---|---|
{securityToken} |
$_security->getToken() |
{securityTokenKey} |
$_security->getTokenKey() |
Features from Nette
You can use all the great features from the Latte.
Latte Template Engine
See more on official documentation.
You can use macros and filters.
Macros
Classic macros
<ul> {foreach $users as $user} <li>{$user->name}</li> {/foreach} </ul>
N-macros
<ul n:foreach="$users as $user"> <li>{$user->name}</li> </ul>
Filters
{var $time => time()} It's {$time|date:'d.m.Y'} at {$time|date:'H:i:s'}
Latte Macros
See more on official documentation.
| Variable and expression printing | |
|---|---|
{$variable} |
prints an escaped variable |
| `{$variable | noescape}` |
{expression} |
prints an escaped expression |
| `{expression | noescape}` |
| Conditions | |
|---|---|
{if $cond} … {elseif $cond} … {else} … {/if} |
if condition |
{ifset $var} … {elseifset $var} … {/ifset} |
if (isset()) condition |
| Loops | |
|---|---|
{foreach $arr as $item} … {/foreach} |
foreach loop |
{for expr; expr; expr} … {/for} |
for loop |
{while expr} … {/while} |
while loop |
{continueIf $cond} |
conditional jump to the next iteration |
{breakIf $cond} |
conditional loop break |
{first} … {/first} |
prints if first iteration |
{last} … {/last} |
prints if last iteration |
{sep} … {/sep} |
separator |
| Variables | |
|---|---|
{var $foo = value} |
variable creation |
{default $foo = value} |
default value when variable isn't declared |
{capture $var} … {/capture} |
captures a section to a variable |
| Engine | |
|---|---|
{include 'file.latte'} |
includes a template from other file |
{cache $key} … {/cache} |
caches a template section |
{php expression} |
evaluates an expression without printing it |
{* comment text *} |
a comment (removed from evaluation) |
{syntax mode} |
switches the syntax at runtime |
{use Class} |
loads new user-defined macros |
{l} or {r} |
prints { and } characters, respectively |
{contentType $type} |
switches the escaping mode and sends HTTP header |
{status $code} |
sets an HTTP status code |
| HTML tag attributes | |
|---|---|
n:class |
smart class attribute |
n:attr |
smart HTML attributes |
n:ifcontent |
Omit empty HTML tag |
n:tag-if |
Omit HTML tag if condition is FALSE |
| Translations | |
|---|---|
{_}Text{/_} |
translates a text |
{_expression} |
translates an expression and prints it with escaping |
| Blocks, layouts, template inheritance | |
|---|---|
{block block} |
block definition and immediate print out |
{define block} |
block defintion for future use |
{include block} |
inserts a block |
{include mytemplate.latte} |
inserts a template |
{includeblock 'file.latte'} |
loads blocks from external template |
{layout 'file.latte'} |
specifies a layout file |
{extends 'file.latte'} |
alias for {layout} |
{ifset #block} … {/ifset} |
condition if block is defined |
Latte Filters
See more on official documentation.
| String modification | |
|---|---|
truncate (length, append = '..') |
shortens the length preserving whole words |
substr (offset [, length]) |
returns part of the string |
trim (charset = whitespace) |
strips whitespace or other characters from the beginning and end of the string |
striptags |
removes HTML tags |
strip |
removes whitespace |
webalize (charlist = '...', lower = TRUE) |
returns string in cool URL form |
toAscii |
removes accents |
indent (level = 1, char = "\t"")" |
indents the text from left with number of tabs |
replace (search, replace = '') |
replaces all occurrences of the search string with the replacement |
replaceRE (pattern, replace = '') |
replaces all occurrences according to regular expression |
padLeft (length, pad = ' ') |
completes the string to given length from left |
padRight (length, pad = ' ') |
completes the string to given length from right |
repeat (count) |
repeats the string |
implode (glue = '') |
joins an array to a string |
nl2br |
new lines with |
| Letter casing | |
|---|---|
lower |
makes a string lower case |
upper |
makes a string upper case |
firstUpper |
makes the first letter upper case |
capitalize |
lower case, the first letter of each word upper case |
| Formatting | |
|---|---|
date (format) |
formats date |
number (decimals = 0, decPoint = '.') |
format number |
bytes (precision = 2) |
formats size in bytes |
| Other | |
|---|---|
noescape |
prints a variable without escaping |
dataStream (mimetype = detect) |
Data URI protocol conversion |
escapeurl |
escapes parameter in URL |
length |
returns length of a string |
null |
flushes the input, returns nothing |
Features from your own
Writing macros
- Define macros
use Latte\Compiler; use Latte\Macros\MacroSet; use Phalette\Platte\Latte\MacroInstaller; final class MyUltraMacros extends MacroSet implements MacroInstaller { public static function install(Compiler $compiler) { $me = new static($compiler); $me->addMacro(...); } }
- Register to
LatteFatory
$factory = new LatteFactory(); $factory->addMacro(new MyUltraMacros);
Writing filters
- Define filters
final class MyUltraFilters { public static function hi($name) { return "Hi $name"; } }
- Register to
LatteFatory
$factory = new LatteFactory(); $factory->addFilter('sayhi', ['MyUltraFilters', 'hi']);
Development
This package was maintained by these authors.
Consider to support contributte development team. Also thank you for using this package.
phalette/platte 适用场景与选型建议
phalette/platte 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57.18k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「templating」 「twig」 「nette」 「latte」 「engine」 「phalcon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phalette/platte 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phalette/platte 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phalette/platte 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
Twig extensions for Tracy Debugger
A Processor for Markup written in PHP. Allows extraction of Markup into a data structure, orchestrated nested manipulation of said structure, and output as (optimized) Markup.
统计信息
- 总下载量: 57.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-09-03