SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
WordPress-Themes
mit Twig entwickeln
Walter Ebert @wltrd
WordCamp Berlin 14. November 2015
https://www.flickr.com/photos/37872410@N00/4653843463/https://www.flickr.com/photos/37872410@N00/4653843463/
Walter Ebert
@wltrd
walterebert.de
slideshare.net/walterebert
http://twig.sensiolabs.org/http://twig.sensiolabs.org/
Vorteile von Twig
• Trennung von HTML und PHP
• Einfacher für Anfänger
• Mehr Sicherheit
• Vererbung von Templates
• Erfahrung aus andere PHP-Projekte nutzen
Projekte die Twig nutzen
• Symfony
• Drupal 8
• EZ Publish
• Bolt
• Grav
• Craft
• Slim
• Sculpin
• (Laravel)
• ...
Projekte die Twig nutzen
• Symfony
• Drupal 8
• EZ Publish
• Bolt
• Grav
• Craft
• Slim
• Sculpin
• (Laravel)
• ...
Drupal 8 Release Party
19. November 2015
http://drupalberlin.de/
http://www.drupical.com/
#Celebr8D8
Nachteile von Twig
• Extra Template-Sprache
• Code ist (etwas) langsamer
https://wordpress.org/plugins/timber-library/https://wordpress.org/plugins/timber-library/
https://github.com/jarednova/timber/wikihttps://github.com/jarednova/timber/wiki
Twig PHP-Erweiterung
git clone https://github.com/twigphp/Twig.git
cd Twig/ext/twig
phpize
./configure
make
sudo make install
php.ini
[twig]
extension=twig.so
Twig-Syntax
{{ }} // Ausgabe
{% %} // Logik
{# #} // Kommentar
single.twig
{# Dies ist ein Beitrag #}
{% extends "base.twig" %}
{% block content %}
<h1 class="site-title">{{ foo }}</h1>
<h2>{{ post.title|upper }}</h2>
{% if post.thumbnail %}
<img src="{{ post.thumbnail.src }}" />
{% endif %}
<div class="content">{{ post.content }}</div>
{% endblock %}
single.twig
{# Dies ist ein Beitrag #}
{% extends "base.twig" %}
{% block content %}
<h1 class="site-title">{{ foo }}</h1>
<h2>{{ post.title|upper }}</h2>
{% if post.thumbnail %}
<img src="{{ post.thumbnail.src }}" />
{% endif %}
<div class="content">{{ post.content }}</div>
{% endblock %}
single.twig
{# Dies ist ein Beitrag #}
{% extends "base.twig" %}
{% block content %}
<h1 class="site-title">{{ foo }}</h1>
<h2>{{ post.title|upper }}</h2>
{% if post.thumbnail %}
<img src="{{ post.thumbnail.src }}" />
{% endif %}
<div class="content">{{ post.content }}</div>
{% endblock %}
single.twig
{# Dies ist ein Beitrag #}
{% extends "base.twig" %}
{% block content %}
<h1 class="site-title">{{ foo }}</h1>
<h2>{{ post.title|upper }}</h2>
{% if post.thumbnail %}
<img src="{{ post.thumbnail.src }}" />
{% endif %}
<div class="content">{{ post.content }}</div>
{% endblock %}
single.php
<?php
$context = Timber::get_context();
$context['foo'] = 'Bar!';
$context['post'] = new TimberPost();
Timber::render( 'single.twig', $context );
Posts
// Posts
$context['posts'] = Timber::get_posts();
// WP_Query
$args = [
'post_type' => 'custom_post_type',
'post_status' => 'publish',
'posts_per_page' => 5,
];
$context['posts'] = Timber::get_posts( $args );
Posts
{% for post in posts %}
<article id="post-{{ post.ID }}">
<h1>
<a href="{{ post.link }}">{{ post.title }}</a>
</h1>
<div class="date">
{{ post.date }}
</div>
<div class="excerpt">
{{ post.content|excerpt(55) }}
</div>
</article>
{% endfor %}
Übersetzungen
<?php _e( 'Sorry, no posts.', 'meins' ); ?>
->
{{ __('Sorry, no posts.', 'meins') }}
WordPress-Funktionen
<?php get_search_form(); ?>
->
{{ fn('get_search_form') }}
Advanced Custom Fields
<h3>{{ post.title }}</h3>
<div class="intro-text">
{{ post.get_field('meins_intro_text') }}
</div>
{% for item in post.get_field('meins_repeater') %}
<article class="item">
<h1>{{ item.name }}</h1>
{{ item.info }}
</article>
{% endfor %}
https://wordpress.org/plugins/advanced-custom-fields/
Advanced Custom Fields Pro
<h3>{{ post.title }}</h3>
<div class="intro-text">
{{ post.get_field('meins_intro_text') }}
</div>
{% for item in post.get_field('meins_repeater') %}
<article class="item">
<h1>{{ item.name }}</h1>
{{ item.info }}
</article>
{% endfor %}
http://www.advancedcustomfields.com/
http://notlaura.com/the-twig-for-timber-cheatsheet/http://notlaura.com/the-twig-for-timber-cheatsheet/
https://github.com/upstatement/timber-starter-themehttps://github.com/upstatement/timber-starter-theme
Praxisbeispiele
https://github.com/jarednova/timber/wiki/Showcase
https://github.com/laras126/karenmcgrane
https://github.com/laras126/mtnmeister-theme
https://github.com/laras126/dijifi-theme
https://github.com/search?utf8=%E2%9C%93&q=timber+wordp
ress&type=Repositories&ref=searchresults
walter.ebert.engineering
@wltrd
walterebert.de
slideshare.net/walterebert

Más contenido relacionado

La actualidad más candente

Tworzenie wtyczek dla TinyMCE 4.* - WordUp Kraków
Tworzenie wtyczek dla TinyMCE 4.* - WordUp KrakówTworzenie wtyczek dla TinyMCE 4.* - WordUp Kraków
Tworzenie wtyczek dla TinyMCE 4.* - WordUp KrakówTomasz Dziuda
 
Front-end en WordPress
Front-end en WordPressFront-end en WordPress
Front-end en WordPressDisonancias
 
Intro to jQuery UI
Intro to jQuery UIIntro to jQuery UI
Intro to jQuery UIappendTo
 
Joomla in a Box – A Vagrant box for local Joomla development
Joomla in a Box – A Vagrant box for local Joomla developmentJoomla in a Box – A Vagrant box for local Joomla development
Joomla in a Box – A Vagrant box for local Joomla developmentJoomlatools
 
Zend bootstrap
Zend bootstrapZend bootstrap
Zend bootstrapneuros
 
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»DataArt
 
Presentación WP Versión Keynote
Presentación WP Versión KeynotePresentación WP Versión Keynote
Presentación WP Versión KeynoteJosé Fonseca
 
Meteor로 만드는 modern web application
Meteor로 만드는 modern web applicationMeteor로 만드는 modern web application
Meteor로 만드는 modern web applicationJaeho Lee
 
Introduction à Marionette
Introduction à MarionetteIntroduction à Marionette
Introduction à MarionetteRaphaël Lemaire
 
Doctype html publi1
Doctype html publi1Doctype html publi1
Doctype html publi1Eddy_TKJ
 

La actualidad más candente (13)

Tworzenie wtyczek dla TinyMCE 4.* - WordUp Kraków
Tworzenie wtyczek dla TinyMCE 4.* - WordUp KrakówTworzenie wtyczek dla TinyMCE 4.* - WordUp Kraków
Tworzenie wtyczek dla TinyMCE 4.* - WordUp Kraków
 
Front-end en WordPress
Front-end en WordPressFront-end en WordPress
Front-end en WordPress
 
Intro to jQuery UI
Intro to jQuery UIIntro to jQuery UI
Intro to jQuery UI
 
Prototype UI
Prototype UIPrototype UI
Prototype UI
 
Joomla in a Box – A Vagrant box for local Joomla development
Joomla in a Box – A Vagrant box for local Joomla developmentJoomla in a Box – A Vagrant box for local Joomla development
Joomla in a Box – A Vagrant box for local Joomla development
 
Why Sass?
Why Sass?Why Sass?
Why Sass?
 
Zend bootstrap
Zend bootstrapZend bootstrap
Zend bootstrap
 
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
Александр Кашеверов «Пара слов о веб - приложениях и что такое Gulp»
 
Presentación WP Versión Keynote
Presentación WP Versión KeynotePresentación WP Versión Keynote
Presentación WP Versión Keynote
 
Meteor로 만드는 modern web application
Meteor로 만드는 modern web applicationMeteor로 만드는 modern web application
Meteor로 만드는 modern web application
 
Introduction à Marionette
Introduction à MarionetteIntroduction à Marionette
Introduction à Marionette
 
Doctype html publi1
Doctype html publi1Doctype html publi1
Doctype html publi1
 
Codigos html
Codigos htmlCodigos html
Codigos html
 

Más de Walter Ebert

FrOSCon 2023: WordPress als ActivityPub-Instanz
FrOSCon 2023: WordPress als ActivityPub-InstanzFrOSCon 2023: WordPress als ActivityPub-Instanz
FrOSCon 2023: WordPress als ActivityPub-InstanzWalter Ebert
 
Hero Video Performance - DrupalCamp Ruhr
Hero Video Performance - DrupalCamp RuhrHero Video Performance - DrupalCamp Ruhr
Hero Video Performance - DrupalCamp RuhrWalter Ebert
 
Sicherheit für WordPress
Sicherheit für WordPressSicherheit für WordPress
Sicherheit für WordPressWalter Ebert
 
WordPress aufräumen - WordCamp Stuttgart
WordPress aufräumen - WordCamp StuttgartWordPress aufräumen - WordCamp Stuttgart
WordPress aufräumen - WordCamp StuttgartWalter Ebert
 
WordPress aufräumen
WordPress aufräumenWordPress aufräumen
WordPress aufräumenWalter Ebert
 
Hero Video Performance
Hero Video PerformanceHero Video Performance
Hero Video PerformanceWalter Ebert
 
WordPress-Webseiten umziehen / online stellen
WordPress-Webseiten umziehen / online stellenWordPress-Webseiten umziehen / online stellen
WordPress-Webseiten umziehen / online stellenWalter Ebert
 
Using browser settings for performance
Using browser settings for performanceUsing browser settings for performance
Using browser settings for performanceWalter Ebert
 
Das richtige WordPress-Theme finden
Das richtige WordPress-Theme findenDas richtige WordPress-Theme finden
Das richtige WordPress-Theme findenWalter Ebert
 
WordPress Health Check - WordCamp Würzburg
WordPress Health Check - WordCamp WürzburgWordPress Health Check - WordCamp Würzburg
WordPress Health Check - WordCamp WürzburgWalter Ebert
 
WordPress Health Check
WordPress Health CheckWordPress Health Check
WordPress Health CheckWalter Ebert
 
Making WordPress fast(er)
Making WordPress fast(er)Making WordPress fast(er)
Making WordPress fast(er)Walter Ebert
 
Testumgebungen für WordPress
Testumgebungen für WordPressTestumgebungen für WordPress
Testumgebungen für WordPressWalter Ebert
 
Modernism in Web Design
Modernism in Web DesignModernism in Web Design
Modernism in Web DesignWalter Ebert
 
WordPress Multisite
WordPress MultisiteWordPress Multisite
WordPress MultisiteWalter Ebert
 
Weniger aus Bilder holen
Weniger aus Bilder holenWeniger aus Bilder holen
Weniger aus Bilder holenWalter Ebert
 
WordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWalter Ebert
 
High Performance Images
High Performance ImagesHigh Performance Images
High Performance ImagesWalter Ebert
 
HTTPS + Let's Encrypt
HTTPS + Let's EncryptHTTPS + Let's Encrypt
HTTPS + Let's EncryptWalter Ebert
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWalter Ebert
 

Más de Walter Ebert (20)

FrOSCon 2023: WordPress als ActivityPub-Instanz
FrOSCon 2023: WordPress als ActivityPub-InstanzFrOSCon 2023: WordPress als ActivityPub-Instanz
FrOSCon 2023: WordPress als ActivityPub-Instanz
 
Hero Video Performance - DrupalCamp Ruhr
Hero Video Performance - DrupalCamp RuhrHero Video Performance - DrupalCamp Ruhr
Hero Video Performance - DrupalCamp Ruhr
 
Sicherheit für WordPress
Sicherheit für WordPressSicherheit für WordPress
Sicherheit für WordPress
 
WordPress aufräumen - WordCamp Stuttgart
WordPress aufräumen - WordCamp StuttgartWordPress aufräumen - WordCamp Stuttgart
WordPress aufräumen - WordCamp Stuttgart
 
WordPress aufräumen
WordPress aufräumenWordPress aufräumen
WordPress aufräumen
 
Hero Video Performance
Hero Video PerformanceHero Video Performance
Hero Video Performance
 
WordPress-Webseiten umziehen / online stellen
WordPress-Webseiten umziehen / online stellenWordPress-Webseiten umziehen / online stellen
WordPress-Webseiten umziehen / online stellen
 
Using browser settings for performance
Using browser settings for performanceUsing browser settings for performance
Using browser settings for performance
 
Das richtige WordPress-Theme finden
Das richtige WordPress-Theme findenDas richtige WordPress-Theme finden
Das richtige WordPress-Theme finden
 
WordPress Health Check - WordCamp Würzburg
WordPress Health Check - WordCamp WürzburgWordPress Health Check - WordCamp Würzburg
WordPress Health Check - WordCamp Würzburg
 
WordPress Health Check
WordPress Health CheckWordPress Health Check
WordPress Health Check
 
Making WordPress fast(er)
Making WordPress fast(er)Making WordPress fast(er)
Making WordPress fast(er)
 
Testumgebungen für WordPress
Testumgebungen für WordPressTestumgebungen für WordPress
Testumgebungen für WordPress
 
Modernism in Web Design
Modernism in Web DesignModernism in Web Design
Modernism in Web Design
 
WordPress Multisite
WordPress MultisiteWordPress Multisite
WordPress Multisite
 
Weniger aus Bilder holen
Weniger aus Bilder holenWeniger aus Bilder holen
Weniger aus Bilder holen
 
WordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwalten
 
High Performance Images
High Performance ImagesHigh Performance Images
High Performance Images
 
HTTPS + Let's Encrypt
HTTPS + Let's EncryptHTTPS + Let's Encrypt
HTTPS + Let's Encrypt
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFM
 

WordPress-Themes mit Twig entwickeln