Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Perch CMS Template Engine
Search
Drew McLellan
September 10, 2013
Technology
0
230
Perch CMS Template Engine
How we wrote a template engine for Perch CMS
Drew McLellan
September 10, 2013
Tweet
Share
More Decks by Drew McLellan
See All by Drew McLellan
HTML5 APIs PHP Yorkshire 2017
drewm
1
180
HTML5 APIs Confoo Montreal
drewm
1
260
PHP Payments with Omnipay
drewm
0
110
HTML5 APIs Confoo Vancouver
drewm
0
280
Learn to Love Regular Expressions
drewm
0
150
Ecommerce Projects with Moltin
drewm
0
690
Writing Portable PHP
drewm
0
120
Getting to Grips with Regular Expressions
drewm
1
270
Back to Front Performance - Oct 2013
drewm
0
130
Other Decks in Technology
See All in Technology
日本Rubyの会の構造と実行とあと何か / hokurikurk01
takahashim
1
310
なぜフロントエンド技術を追うのか?なぜカンファレンスに参加するのか?
sakito
9
1.9k
2025 DORA Reportから読み解く!AIが映し出す、成果を出し続ける組織の共通点 #開発生産性_findy
takabow
3
1.1k
モバイルゲーム開発におけるエージェント技術活用への試行錯誤 ~開発効率化へのアプローチの紹介と未来に向けた展望~
qualiarts
0
280
たかが特別な時間の終わり / It's Only the End of Special Time
watany
2
270
プロダクトマネジメントの分業が生む「デリバリーの渋滞」を解消するTPMの越境
recruitengineers
PRO
3
420
Digitization部 紹介資料
sansan33
PRO
1
6.1k
タグ付きユニオン型を便利に使うテクニックとその注意点
uhyo
2
600
Data Hubグループ 紹介資料
sansan33
PRO
0
2.3k
あなたの知らないDateのひみつ / The Secret of "Date" You Haven't known #tqrk16
expajp
0
110
DGX SparkでローカルLLMをLangChainで動かした話
ruzia
1
260
プラットフォームエンジニアリングとは何であり、なぜプラットフォームエンジニアリングなのか
doublemarket
1
540
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
120
20k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Making Projects Easy
brettharned
120
6.5k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Music & Morning Musume
bryan
46
7k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Designing for humans not robots
tammielis
254
26k
Code Review Best Practice
trishagee
73
19k
Visualization
eitanlees
150
16k
Transcript
Drew McLellan Perch CMS grabaperch.com -HOW WE WROTE A- TEMPLATE
ENGINE RDG Geek Night 10th September 2013
L I G H T W E I G H
T PHP CMS FOR SMALL WEBSITES
WE NEEDED A REALLY GOOD TEMPLATE LANGUAGE
-SO- W H A T W A S ALREADY OUT
THERE?
SMARTY (NOT SO SMART)
TWIG (NOT SO MATURE)
JUST PHP -WITH A- DIFFERENT S Y N T A
X
!<perch:content !!!type=”text” !!!id=”heading” !!!label=”Main heading” !!!required=”true” />
<h2><perch:content id="heading" type="text" label="Heading" required="true" title="true" /></h2> <p class="date"><perch:content id="date"
type="date" label="Date" format="%d %B %Y" /></p> <perch:content id="body" type="textarea" label="Body" textile="true" editor="markitup" required="true" />
HTML IS LIKE X M L RIGHT?
<img src="<perch:content id="photo" type="image" label="Photo" />" />
xkcd.com/208
stackoverflow.com/questions/1732348/
! <perch:content type=”text” ! ! id=”heading” label=”Main heading” ! !
required=”true” /> #<perch:content[^>]*/>#
$Tag = new PerchXMLTag( '<perch:content id="foo" bar="baz" />'); echo $Tag->bar;
// baz
#([a-z-]*)="([^"]*)"#
#([a-z-]+)=[\"]([^\"\\ \\]*(?:\\\\.[^\"\\\ \]*)*)[\"]#
-WAIT- REGULAR EXPRESSIONS ARE SLOW, RIGHT?
REGEX ARE SLOW UNLESS YOU NEED THEM
#(<perch:if[^>]*>)(((?! perch:if).)*)</perch:if># ! <perch:if exists=”foo”> ! ! ... loadsamarkup ...
! </perch:if>
-WE NEEDED- A NEW WAY -TO PARSE- TAG PAIRS
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! <perch:if exists=”c”> !
! ! Hello, world. ! ! </perch:if> ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! <perch:if exists=”c”> !
! ! Hello, world. ! ! </perch:if> ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! <perch:if exists=”c”> !
! ! Hello, world. ! ! </perch:if> ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! <perch:if exists=”c”> !
! ! Hello, world. ! ! </perch:if> ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! <perch:if exists=”c”> !
! ! Hello, world. ! ! </perch:if> ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! <perch:if exists=”c”> !
! ! Hello, world. ! ! </perch:if> ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! ! ! !
Hello, world. ! ! ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
<perch:if exists=”a”> ! <perch:if exists=”b”> ! ! ! ! !
Hello, world. ! ! ! </perch:if> <perch:else /> ! <perch:if exists=”d”> ! ! Goodbye, cruel world. ! </perch:if> </perch:if>
CLOSING TAGS -ARE - EASY
NO MORE WINDOWS CRASHES
MAYBE - WE WILL - REWRITE IT
THANK YOU Perch is at grabaperch.com On most things, I’
am @ drewm