Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
220
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
140
HTML5 APIs Confoo Montreal
drewm
1
210
PHP Payments with Omnipay
drewm
0
100
HTML5 APIs Confoo Vancouver
drewm
0
250
Learn to Love Regular Expressions
drewm
0
110
Ecommerce Projects with Moltin
drewm
0
680
Writing Portable PHP
drewm
0
96
Getting to Grips with Regular Expressions
drewm
1
250
Back to Front Performance - Oct 2013
drewm
0
120
Other Decks in Technology
See All in Technology
アジャイルチームが変化し続けるための組織文化とマネジメント・アプローチ / Agile management that enables ever-changing teams
kakehashi
3
3.3k
ゼロからわかる!!AWSの構成図を書いてみようワークショップ 問題&解答解説 #デッカイギ #羽田デッカイギおつ
_mossann_t
0
1.5k
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
3
440
re:Invent2024 KeynoteのAmazon Q Developer考察
yusukeshimizu
1
140
2025年の挑戦 コーポレートエンジニアの技術広報/techpr5
nishiuma
0
140
デジタルアイデンティティ人材育成推進ワーキンググループ 翻訳サブワーキンググループ 活動報告 / 20250114-OIDF-J-EduWG-TranslationSWG
oidfj
0
520
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
170
AWS re:Invent 2024 recap in 20min / JAWSUG 千葉 2025.1.14
shimy
1
100
2024年活動報告会(人材育成推進WG・ビジネスサブWG) / 20250114-OIDF-J-EduWG-BizSWG
oidfj
0
210
コロプラのオンボーディングを採用から語りたい
colopl
5
970
深層学習と3Dキャプチャ・3Dモデル生成(土木学会応用力学委員会 応用数理・AIセミナー)
pfn
PRO
0
460
When Windows Meets Kubernetes…
pichuang
0
300
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
YesSQL, Process and Tooling at Scale
rocio
170
14k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Building an army of robots
kneath
302
45k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Six Lessons from altMBA
skipperchong
27
3.6k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.5k
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