joseym/li3_partials
Composer 安装命令:
composer require joseym/li3_partials
包简介
The partial plugin for Lithium(li3) provides flexibility to pass template sections from view to the layout.
README 文档
README
Plugin to pass template sections from view to the layout.
Installation
-
Clone/Download the plugin into your app's
librariesdirectory. -
Tell your app to load the plugin by adding the following to your app's
config/bootstrap/libraries.php:Libraries::add('li3_partials');
Features
- Assign strings or entire blocks of markup to a partial.
Usage
Blocks
There have been a number of times I was working on a project and had a clean layout rendered but the client required that something in the layout change based on what view was rendered. I used elements and view context asignments for a while but that was neither elegant or enjoyable.
This is designed as a way to pass markup changes to section in a layout based on your view.
wrap the markup you want passed to the layout in <partial></partial> tags with a name attribute.
``` html
<partial name="sidebar"><h2>Sidebar for this view!</h2></partial>
```
There are 2 ways to print a blocked partial in your view
1. Call the blocks partial name and assign type `block`
``` php
<?php echo $this->partial->sidebar(array('type' => 'block')); ?>
```
2. Call a partial block and pass the partials name
``` php
<?php echo $this->partial->block('sidebar');?>
```
Anywhere that you decide to place either of those will render the partial that was defined in your view at that location.
Strings
Similar to blocks, this method is used to pass strings of text to a layout.
"Why?" asks you, "Good question!" I reply
Think in terms of a page description or keywords, these may need to change based on a page view but I could find no easy way to get these requirements to the layout.
In the head of your view template (or anywhere, really, I just think it's cleaner to keep these together at the top) add:
``` php
<?php $this->partial->keywords('awesome, li3, github, php, partials, woot, nifty, grand, pie, unicorns, alfalfa sprouts'); ?>
```
It doesn't matter what you name this method, just keep in mind that that name will be how you call it in the layout.
Ok, so we defined keywords for our view! lets add them to the meta tag
``` html
<meta name="keywords" content="<?php echo $this->partial->keywords(); ?>" />
```
The plugin will find the stored keywords partial and render its contents where it was called.
There is also a wrapper to ensure you only pull strings - much like blocks
<?php echo $this->partial->string('keyword'); ?>
"That's foolish, it's easier just to use the other method!" you exclaim. Hold tight, Fredword! I'll explain why you might want to do this below.
Sharing Names
There may be a case where you define both a partial string and partial block with the same name. To ensure that you pull the right one thee are 2 methods for each (actually 3 for .
Strings
<?php echo $this->partial->string('methodName'); ?> <?php echo $this->partial->methodName(array('type' => 'string')); ?>
Blocks
<?php echo $this->partial->block('methodName'); ?> <?php echo $this->partial->methodName(array('type' => 'block')); ?>
To come
- I plan on adding enhanced cache features to this so the rendering engine isn't constantly parsing templates for partials
- Dynamic partials - support for a data schema to auto load partials from a database.
- Drink a beer. Why not?
Contribute
Have ideas for improvements or features? Send a pull request, I would welcome collaboration!
joseym/li3_partials 适用场景与选型建议
joseym/li3_partials 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 209 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 joseym/li3_partials 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joseym/li3_partials 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 209
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-02