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
Uvod u TWIG - PHP template engine
Search
DaFED
August 16, 2013
Programming
0
110
Uvod u TWIG - PHP template engine
DaFED #13
Speaker: Dejan Dexter Duduković, Eton Digital
DaFED
August 16, 2013
Tweet
Share
More Decks by DaFED
See All by DaFED
A Storybook with Angular
dafed
0
180
Search & Destroy
dafed
0
110
Why Fast Matters
dafed
1
220
Leadership through Change
dafed
0
220
Upotreba VR tehnologija u real estate-u
dafed
0
250
Virtuelna Realnost uzvraća udarac
dafed
0
150
PHP i MongoDB iz prve ruke
dafed
0
260
PHP Middleware i njegova upotreba
dafed
0
200
Asinhrone budućnosti i verteksi
dafed
0
270
Other Decks in Programming
See All in Programming
Cache Me If You Can
ryunen344
2
1.4k
パッケージ設計の黒魔術/Kyoto.go#63
lufia
3
440
デザイナーが Androidエンジニアに 挑戦してみた
874wokiite
0
470
AWS発のAIエディタKiroを使ってみた
iriikeita
1
190
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
130
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
3
300
HTMLの品質ってなんだっけ? “HTMLクライテリア”の設計と実践
unachang113
4
2.9k
機能追加とリーダー業務の類似性
rinchoku
2
1.3k
Improving my own Ruby thereafter
sisshiki1969
1
160
Amazon RDS 向けに提供されている MCP Server と仕組みを調べてみた/jawsug-okayama-2025-aurora-mcp
takahashiikki
1
110
rage against annotate_predecessor
junk0612
0
170
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
1.5k
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
54
11k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
A better future with KSS
kneath
239
17k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Bash Introduction
62gerente
615
210k
Code Review Best Practice
trishagee
70
19k
A Modern Web Designer's Workflow
chriscoyier
696
190k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
How to Ace a Technical Interview
jacobian
279
23k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
112
20k
Transcript
PHP template engine Dejan Dexter Dudukovic Front-End developer EtonDigital
Tvorac twiga: Fabien Potencier ( Symfony ) Twig
je moderan templejt sistem za PHP Twig je – Fast , Flexible , Secure Sve sto vam treba je dokumentacija.
Symfony Drupal 8 ( in core )
CodeIgniter ( Spark , extension ) Zend ( extension ) Laravel Twig ( bundles ) Magento 2 WordPress ( plugin ) ……
Lako !!!! - Composer (recommended ) - Git –
( development version ) - PEAR package
Ucitavanje biblioteke: require_once 'vendor/twig/twig/lib/Twig/Autoloader.php'; Registrovanje loadera: Twig_Autoloader::register(); Kreiranje loader objekta
– ( folder za template fajlove ) $loader = new Twig_Loader_Filesystem('templates/'); Krairanje twig objekta i setovanje konfiguracije $twig = new Twig_Environment($loader , array( 'cache' => 'cache', // opcija za kesiranje stranica 'debug' => true // debug mode u development fazi ));
- Nadogradnja Twig funkcionalnosti kroz eksenzije $twig->addExtension( new Twig_Extension_Debug() );
- Dodavanje ( PHP funkcija u twig ) $twig->addFunction( new Twig_SimpleFunction('krumo', ‘tKrumo') );
Postoje 2 nacina za ucitavanje template fajlova. 1. Ucitavanje template
fajla sa prosledjenim varijablama ( promenjive ) I smestanje HTML,Twig koda u varijablu. $data['content'] = $twig->render('users.twig' , $user ); 2. Ucitavanje temlate fajla i prikazivanje na stranici ( zavrsni korak ) $twig->display( 'template.twig' , $data );
Variable: PHP: <?php echo $var ?> <?php echo htmlspecialchars($var, ENT_QUOTES,
'UTF-8') ?> Twig: {{ variable }} {{ variable|escape }} Funkcije i logike: {% funkcija() %} {% for user in users %} * {{ user.name }} {% else %} No user have been found. {% endfor %}
Tags ( macro , autoescape , extends , set
, include , filter ) Filters Functions ( date , dump , random ) Operators Test ( empty , even , null )
None