phptal with cakephp
DESCRIPTION
第一回デザイナー向けCakePHP勉強会のLT発表資料です。PHPTALの概要、CakePHPでの利用方法について紹介します。TRANSCRIPT
PHPTAL with CakePHP
July 2011
デザイナー向けCakePHP勉強会
About Me
• WEB Developer / PHP / CakePHP / HTML / CSS / jQuery / MySQL / iPhone / 佐賀 / 福岡 / 島根 / 熊本 / プリン / キイロイトリ / ミッフィー / no more トマト
• BLOG: http://php-tips.com/
• TWITTER: @nojimage
名前: 野島 隆(のじま たかし)所属:イラスティックコンサルタンツ株式会社
Template Engine
Template Engine
•データとテンプレートを合成してHTMLなどを出力する
•Smarty, Twig, PHP, PHPTAL, etc...
Data Template
TemplateEngine
HTML,RSS Feed,
etc...
PHPTAL
TAL
•表示のためのロジックをXHTML(XML)の属性として記述する
•http://wiki.zope.org/ZPT/TAL
Templae Attribute Language
•表示のためのロジックをXHTML(XML)の属性として記述する
•http://wiki.zope.org/ZPT/TAL
PHPTAL
•ZopeのTALをPHPへ移植したもの
•公式http://phptal.org/
•日本語マニュアル
http://phptal.org/manual/ja/
code
氏名と電話番号の表
Data
$people = array( array( ‘name’ => ‘Taro Yamada’, ‘phone’ => ‘090-0000-0000’ ), array( ‘name’ => ‘Hisateru Tanaka’, ‘phone’ => ’06-XXXX-XXXX’ ), // ...);
HTML
<table> <tr> <th>Name</th> <th>Phone</th> </tr> <tr> <td>person's name</td> <td>person's phone</td> </tr> <tr> <td>sample name</td> <td>sample phone</td> </tr></table>
<table> <tr> <th>Name</th> <th>Phone</th> </tr> <tr> <td>person's name</td> <td>person's phone</td> </tr> <tr> <td>sample name</td> <td>sample phone</td> </tr></table>
この部分をデータの件数分繰り返して表示したい
PHP
<table> <tr> <th>Name</th> <th>Phone</th> </tr> <?php foreach ($people as $person) : ?> <tr> <td><?php echo $person['name']; ?></td> <td><?php echo $person['phone']; ?></td> </tr> <?php endforeach; ?></table>
Smarty
is not smart...
<table> <tr> <th>Name</th> <th>Phone</th> </tr> {foreach from=$people item=person} <tr> <td>{$person.name}</td> <td>{$person.phone}</td> </tr> {/foreach}</table>
PHPTAL
<table> <tr> <th>Name</th> <th>Phone</th> </tr> <tr tal:repeat="person people"> <td tal:content="person/name">person's name</td> <td tal:content="person/phone">person's phone</td> </tr> <tr tal:replace=""> <td>sample name</td> <td>sample phone</td> </tr></table>
<table> <tr> <th>Name</th> <th>Phone</th> </tr> <tr tal:repeat="person people"> <td tal:content="person/name">person's name</td> <td tal:content="person/phone">person's phone</td> </tr> <tr tal:replace=""> <td>sample name</td> <td>sample phone</td> </tr></table>
HTMLの属性として記述
in Browser
in Browser
in Browser
in Browser
元のHTMLそのまま
表示のためのロジックを組み込んでも
HTMLを壊さない
ロジックを追加した後でもデザイナー側で
見た目の調整が可能
PHPTAL
•シンプルな構文1. tal:define2. tal:condition3. tal:repeat4. tal:omit-tag5. tal:replace6. tal:content
7. tal:attributes8. tal:on-error9. metal:define-macro10. metal:use-macro11. metal:define-slot12. metal:fill-slot
PHPTAL is Smart!
つまり
PHPTALはモテる!
かも。
PHPTALwith
CakePHP
CakePHP-TALTALplugin
https://github.com/nojimage/CakePHP-TALTAL
Feature
•拡張子html, xhtml, zptのテンプレートをPHPTALで解釈!!
•通常のctpは、生PHPのテンプレートとして利用OK!
•テーマ機能対応!
Feature
•url, fullurlモディファイアの追加•cake:helper属性の追加
Installation
•git clone or download
•set to plugins/taltal
•write to AppControllerclass AppController extends Controller { // ...(snip)
public $view = 'Taltal.Phptal';
// ...(snip)}
Let’s Try PHPTAL!!次のプロジェクトの
テンプレートエンジンはPHPTALで♡
CakePHP-TALTAL
• https://github.com/nojimage/CakePHP-TALTAL
•since 2011/06/01
•version 0.3.1
人柱募集!!
ご静聴ありがとうございました