Drupal 8 Theming Deep Dive



Similar documents
Creating a Drupal 8 theme from scratch

Drupal 8 Theming. Exploring Twig & Other Frontend Changes CROWD. Communications Group, LLC CROWD. Communications Group, LLC

FormAPI, AJAX and Node.js

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

Drupal and ArcGIS Yes, it can be done. Frank McLean Developer

HOW TO CREATE THEME IN MAGENTO 2

Drupal CMS for marketing sites

Elgg 1.8 Social Networking

The truth about Drupal

Bubble Code Review for Magento

MASTER DRUPAL 7 MODULE DEVELOPMENT

Citrix StoreFront. Customizing the Receiver for Web User Interface Citrix. All rights reserved.

JAVASCRIPT, TESTING, AND DRUPAL

Unlocking the Java EE Platform with HTML 5

Using jquery and CSS to Gain Easy Wins in CiviCRM

Site Audit ( /site_audit) Generated on Fri, 22 Aug :14:

Auditing Drupal sites for performance, content and optimal configuration

Interspire Website Publisher Developer Documentation. Template Customization Guide

Django Assess Managed Nicely Documentation

Terms and Definitions for CMS Administrators, Architects, and Developers

The importance of Drupal Cache. Luis F. Ribeiro Ci&T Inc. 2013

WEB DEVELOPMENT COURSE (PHP/ MYSQL)

BT CONTENT SHOWCASE. JOOMLA EXTENSION User guide Version 2.1. Copyright 2013 Bowthemes Inc.

Sitecore Dashboard User Guide

How To Use Query Console

Creating an newsletter using SimpleNews and phplist

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Responsive Web Design for Drupal

MAGENTO TRAINING PROGRAM

Responsive HTML and Drupal

DEMO ONLY VERSION. Easy CramBible Lab M Magento Front End Developer Certification Exam. ** Single-user License **

Developing ASP.NET MVC 4 Web Applications MOC 20486

Workshop on Using Open Source Content Management System Drupal to build Library Websites Hasina Afroz Auninda Rumy Saleque

Drupal 8 The site builder's release

SharePoint 2010 End User - Level II

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

Configuring the JEvents Component

Localizing dynamic websites created from open source content management systems

Testking.M Q

Using your Drupal Website Book 1 - Drupal Basics

Module Customer Ratings and Reviews Pro + Google Rich Snippets Module

Portals and Hosted Files

Everything you ever wanted to know about Drupal 8*

EXAM - M Magento Front End Developer. Buy Full Product.

(An) Optimal Drupal 7 Module Configuration for Site Performance JOE PRICE

How To Change Your Site On Drupal Cloud On A Pcode On A Microsoft Powerstone On A Macbook Or Ipad (For Free) On A Freebie (For A Free Download) On An Ipad Or Ipa (For

Web Design Technology

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

Theming on Drupal 7. Working with Omega s Responsive Framework

ireview Template Manual

BUILDING MULTILINGUAL WEBSITES WITH DRUPAL 7

Magento 1.4 Themes Design

App Building Guidelines

Simple Tips to Improve Drupal Performance: No Coding Required. By Erik Webb, Senior Technical Consultant, Acquia

JTouch Mobile Extension for Joomla! User Guide

Drupal 8. Core and API Changes Shabir Ahmad MS Software Engg. NUST Principal Software Engineser PHP/Drupal

Expanded contents. Section 1. Chapter 2. The essence off ASP.NET web programming. An introduction to ASP.NET web programming

Beginning Web Development with Node.js

Mistral Joomla Template

Dashboard Builder TM for Microsoft Access

Debugging JavaScript and CSS Using Firebug. Harman Goei CSCI 571 1/27/13

Module Google Rich Snippets + Product Ratings and Reviews

Developing ASP.NET MVC 4 Web Applications

Developer Tutorial Version 1. 0 February 2015

ultimo theme Update Guide Copyright Infortis All rights reserved

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

Commerce Services Documentation

INSTALLATION AND CONFIGURATION MANUAL ENCODER

MASTERTAG DEVELOPER GUIDE

Create interactive web graphics out of your SAS or R datasets

Who? Wolfgang Ziegler (fago) Klaus Purer (klausi) Sebastian Gilits (sepgil) epiqo Austrian based Drupal company Drupal Austria user group

Build it with Drupal 8

AUDIT REPORT EXAMPLE

Developing Exceptional Mobile and Multi-Channel Applications using IBM Web Experience Factory IBM Corporation 1

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

Learning Magento Theme Development

Module Google Rich Snippets + Product Ratings and Reviews

5 Mistakes to Avoid on Your Drupal Website

Drupal Performance Tuning

How We Did It. Unique data model abstraction layer to integrate, but de-couple EHR data from patient website design.

Developing Mobile Websites with Responsive Web Design and jquery Mobile

Magento Extension Developer s Guide

Interactive Data Visualization for the Web Scott Murray

Basic tutorial for Dreamweaver CS5

Website Builder Documentation

Cache Configuration Reference

GETTING STARTED WITH DRUPAL. by Stephen Cross

Porting Existing PhoneGap Apps to Tizen OS - Development Story

Wakanda Studio Features

Page Editor Recommended Practices for Developers

Slide.Show Quick Start Guide

The Search API in Drupal 8. Thomas Seidl (drunken monkey)

Transcription:

Drupal 8 Theming Deep Dive

Romain JARRAUD Trainer/consultant Trained People @romainjarraud (mainly in french)

What is theming?

Theming? Fonctionnal Display Drupal and modules Theme

Theming? THEMING = HTML output Other outputs could be RSS feed, JSON HEADfull Drupal8 here!

Theming? Modules produce datas. Modules have default renderings. For example, Block module define block.twig.html template which render each block. The theme OVERRIDES the default renderings.

Theming? Theme overrides defaults: html code for every element on the page. styles: font size, colors, images... effets using javascript.

Browser Web Page CSS Request Theme HTML Drupal & modules Content Templates

Create a theme

Create a theme /themes/ive/ive.info.yml

End of the story! Maybe not

Theme files

Templates

TWIG Drupal 8 uses TWIG. TWIG created by Fabien Potencier. Templating system to generate HTML.

TWIG Template name.html.twig: example of page.html.twig for the page template. They hold the HTML tags along with TWIG code.

TWIG (quickly) Display the content of var: {{ var }}. Display any kind of variable (string, array, object): {{ node.title }}. Function: {% if var %} {% endif %}. Comments: {# comment #} Translation: {% trans %} translatable {{ string }} {% endtrans %}. Ready to be translated through Drupal UI!

TWIG (quickly) Filters: {{ date format_date( medium ) }} string: Escaping: {{ text }} (default). No escaping: {{ text passthrough }} (be carreful!). Placeholder : {{ text placeholder }}. {{ content without( links ) }}. {{ string lower }} (upper as well). {{ class_name clean_class }}. {{ id_name clean_id }}.

TWIG /themes/ive/templates/block.html.twig

TWIG Debug Activate Twig Debug in local environment by editing the file /sites/default/services.yml.

TWIG Debug Not enough because Drupal caches entity rendering. Uncomment the loading of a local.settings.php file in /sites/default/settings.php. That file adds a backend cache render service which avoid Drupal to cache.

Template suggestions Depending on context you can ask Drupal to load a specific template. For example to display a node Drupal uses node.html.twig. But it can use node-- article.html.twig (if it exists!) for any node of type article.

Template suggestions A module defines suggestions with hook_theme_suggestions_hook(). Other modules or themes can add suggestions with hook_theme_suggestions_alter() or hook_theme_suggestions_hook_alter().

Template suggestions (Those comments are shown thanks to TWIG Debug mode)

Override Copy original file into theme template folder. Rename it if necessary. Empty theme registry. Do what you want!

Preprocess functions

Preprocess functions $variables Modules preprocess $variables Theme preprocess $variables Default preprocess Template

Called functions order Theme suggestions MODULE_theme_suggestions_HOOK(array $variables) OTHERMODULE_theme_suggestions_alter(array &$suggestions, array $variables, $hook) OTHERMODULE_theme_suggestions_HOOK_alter(array &$suggestions, array $variables) THEME_theme_suggestions_alter(array &$suggestions, array $variables, $hook) THEME_theme_suggestions_HOOK_alter(array &$suggestions, array $variables) Preprocess template_preprocess_hook(array &$variables) OTHERMODULE_preprocess(array &$variables, $hook) OTHERMODULE_preprocess_HOOK(array &$variables) THEME_preprocess(array &$variables, $hook) THEME_preprocess_HOOK(array &$variables)

Librairies

Librairies No more manually asset loading. Bye bye drupal_add_css(), drupal_add_js() and drupal_add_library()! Must add any asset through a library. Drupal takes care of libraries loading and dependencies.

Librairies Declaration Loading

Libraries declaration /themes/ive/ive.libraries.yml

Libraries loading Loading from /themes/ive/ive.info.yml

Libraries loading Loading from a template file /themes/ive/templates/block.html.twig

Libraries loading Loading from /themes/ive/ive.theme using THEME_page_attachments_alter()

Libraries loading Loading from /themes/ive/ive.theme using a preprocess fonction

Library dependency No javascript loaded for anonymous users. Dependencies should be explicit. /themes/ive/ive.libraries.yml

From PHP to JS /themes/ive/ive.theme /themes/ive/js/ive.js

Breakpoints

Breakpoints Breakpoints are exposed on the server side. For example, images can be loaded depending on those breakpoints (using Responsive Image module).

Breakpoints /themes/ive/ive.breakpoints.yml

Breakpoints

Configuration

Configuration How to add settings in the backoffice. Each theme gets its own default form. Alter the form with THEME_form_system_theme_settings_alter() (using the Form API).

Configuration /themes/ive/config/install/ive.settings.yml Defines: ive.settings configuration. «ive» with its default value «one». This configuration is loaded during installation.

Configuration /themes/ive/ive.theme

Configuration

Theme hook declaration

Theme hook declaration Each theme hook is associated with a template file. Each theme hook got its own preprocess function (template_preprocess_hook()) and theme suggestions function (MODULE_theme_suggestions_HOOK()).

Theme hook declaration /modules/simple/simple.module

Theme hook declaration /modules/simple/src/controller/simple.php

A few more things

Everything is a bloc (nearly): breadcrumb, messages Logo format is SVG. Base theme Classy. No more theme functions but templates instead. No more theme() fonction but Render Arrays. No more process functions. PLEASE, no more database queries in templates!!!

Conclusion Not so many things to learn compared to Drupal 7.! Easier with Drupal 8!

Thanks!

Q&A