SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Power to the Frontender
Layout and data manipulation with Twig
@NikGalatis @nkostop
The Team
without the monkey suits
2
I started wefixit dreaming about fixing the web. I
believe that Drupal 8 & Twig can make this
dream a reality. Studying UX tactics when not
coding.
Code monkey of Drupal. Maybe its because I’m
working with it for more than 5 years. If there is a
challenge, count me in.
NICK GALATIS
Frontend developer
NICK KOSTOPOULOS
Backend developer
Thank you Morten
Morten has said pretty much everything there is to be said in
Drupal & Twig but we will show how well twig handles some
easy everyday tasks
4
Power To The Frontender
You will hear about
Twig Blocks & Extends Twig Conditionals & Variables Twig Extensions
— What is twig blocks and why they are
useful for scalable and maintainable
code
— How to extend a template file and
why to do it
— How to pass variables from the
extend twig file to the main template
file
— Basic conditionals available in twig
such as if, else etc.
— Set variables depending and check
them with twig conditions
— Display different layouts using block
positions
— Display content in different layouts
all set at by the content creator
— Create a simple module that extends
twig by adding a new function or filter
— Use this new extend to display a
block dynamically anywhere with
twig power
— In this example we are creating an
extension for loading a custom block.
5
Power To The Frontender
You will see
Dynamic Article Layout Dynamic Theme Layout Simple Module Development
— The editor will add the body text
using the WYSIWYG editor
— We will also add some pictures to
the article
— We will choose the desired layout
from a simple dropdown menu
— The website administrator will be
able to move blocks around available
regions and the whole page layout
will adapt
— In our example you will see how
easily when you add one, two or no
sidebar content in those regions, the
grid layout adapts dynamically
depending on the block content
— We will create a simple module that
will extend twig.
— We will create a twig extension that
will be able to print any block directly
from the twig file
Let’s Get Down To Business
Monkey Business
Twig Blocks
Definition
7
Blocks are used for inheritance and act as placeholders and
replacements at the same time.
- Twig Documentation
“ — Enclose code in blocks in main
template file
— Code inside the block tags can
be overridden by extend theme
files
— Blocks can exist inside other
blocks
Twig Extends & Variables Pass
Definition
8
Twig extends can be used to extend a template from another
one.
- Twig Documentation
“ — Start by declaring the file you
are extending
— Override anything you like by
using blocks
— You can also pass variables to
the main template
Twig Extends & Variables Pass
If you don’t use extend…
9
Main theme file
Theme override
Twig Conditionals
Dynamic Theming Is Here
10
The if statement in Twig is comparable with the if statements of
PHP. In the simplest form you can use it to test if an expression
evaluates to true
- Twig Documentation
“ — Simple condition that checks if
there are blocks in regions
sidebar right or sidebar left
— If there are blocks and
statements are true it
dynamically changes the
markup classes
— Control the layout directly from
the back end block layout page
Layout Building Using Conditionals
Content Type Creation
11
— Choose Layout at content
creation level (on content type)
— Variables are set depending on
the selected option
— Conditions change the layout
as needed
Twig Extend & Filter
Display any block anywhere
12
Register the extension as a service
blockTwigExtension.php
Demo Time
The time you’ve been waiting for
Thank You
Questions?
@NikGalatis
14
@nkostop
Power To The Frontender with Drupal 8 and Twig

Weitere ähnliche Inhalte

Ähnlich wie Power To The Frontender with Drupal 8 and Twig

Ähnlich wie Power To The Frontender with Drupal 8 and Twig (20)

Twig in the Wild
Twig in the WildTwig in the Wild
Twig in the Wild
 
Paragraphs at drupal 8.
Paragraphs at drupal 8.Paragraphs at drupal 8.
Paragraphs at drupal 8.
 
SDL Web DXA: A Vision for Modules
SDL Web DXA: A Vision for ModulesSDL Web DXA: A Vision for Modules
SDL Web DXA: A Vision for Modules
 
Modular plugins
Modular pluginsModular plugins
Modular plugins
 
The Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary VersionThe Open-Closed Principle - the Original Version and the Contemporary Version
The Open-Closed Principle - the Original Version and the Contemporary Version
 
Learn reactjs, how to code with example and general understanding thinkwik
Learn reactjs, how to code with example and general understanding   thinkwikLearn reactjs, how to code with example and general understanding   thinkwik
Learn reactjs, how to code with example and general understanding thinkwik
 
PuppetConf 2016: A Tale of Two Hierarchies: Group Policy & Puppet – Matt Ston...
PuppetConf 2016: A Tale of Two Hierarchies: Group Policy & Puppet – Matt Ston...PuppetConf 2016: A Tale of Two Hierarchies: Group Policy & Puppet – Matt Ston...
PuppetConf 2016: A Tale of Two Hierarchies: Group Policy & Puppet – Matt Ston...
 
OpenCms Days 2014 - Responsive bootstrap templates reloaded
OpenCms Days 2014 - Responsive bootstrap templates reloadedOpenCms Days 2014 - Responsive bootstrap templates reloaded
OpenCms Days 2014 - Responsive bootstrap templates reloaded
 
DevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesDevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation Slides
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sites
 
Modular plugins
Modular pluginsModular plugins
Modular plugins
 
OpenCms Days 2015 Modern templates with nested containers
OpenCms Days 2015 Modern templates with nested containersOpenCms Days 2015 Modern templates with nested containers
OpenCms Days 2015 Modern templates with nested containers
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing Company
 
Cognos Data Module Architectures & Use Cases
Cognos Data Module Architectures & Use CasesCognos Data Module Architectures & Use Cases
Cognos Data Module Architectures & Use Cases
 
Meetup: The big change coming to WordPress in 2018 - Gutenberg
Meetup: The big change coming to WordPress in 2018 - GutenbergMeetup: The big change coming to WordPress in 2018 - Gutenberg
Meetup: The big change coming to WordPress in 2018 - Gutenberg
 
Meetup: The big change coming to WordPress in 2018 - Gutenberg
Meetup: The big change coming to WordPress in 2018 - GutenbergMeetup: The big change coming to WordPress in 2018 - Gutenberg
Meetup: The big change coming to WordPress in 2018 - Gutenberg
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
 
Customer FX Technical Reference Sheet
Customer FX Technical Reference SheetCustomer FX Technical Reference Sheet
Customer FX Technical Reference Sheet
 
Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8
 
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
 

Kürzlich hochgeladen

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Kürzlich hochgeladen (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 

Power To The Frontender with Drupal 8 and Twig

  • 1. Power to the Frontender Layout and data manipulation with Twig
  • 2. @NikGalatis @nkostop The Team without the monkey suits 2 I started wefixit dreaming about fixing the web. I believe that Drupal 8 & Twig can make this dream a reality. Studying UX tactics when not coding. Code monkey of Drupal. Maybe its because I’m working with it for more than 5 years. If there is a challenge, count me in. NICK GALATIS Frontend developer NICK KOSTOPOULOS Backend developer
  • 3. Thank you Morten Morten has said pretty much everything there is to be said in Drupal & Twig but we will show how well twig handles some easy everyday tasks
  • 4. 4 Power To The Frontender You will hear about Twig Blocks & Extends Twig Conditionals & Variables Twig Extensions — What is twig blocks and why they are useful for scalable and maintainable code — How to extend a template file and why to do it — How to pass variables from the extend twig file to the main template file — Basic conditionals available in twig such as if, else etc. — Set variables depending and check them with twig conditions — Display different layouts using block positions — Display content in different layouts all set at by the content creator — Create a simple module that extends twig by adding a new function or filter — Use this new extend to display a block dynamically anywhere with twig power — In this example we are creating an extension for loading a custom block.
  • 5. 5 Power To The Frontender You will see Dynamic Article Layout Dynamic Theme Layout Simple Module Development — The editor will add the body text using the WYSIWYG editor — We will also add some pictures to the article — We will choose the desired layout from a simple dropdown menu — The website administrator will be able to move blocks around available regions and the whole page layout will adapt — In our example you will see how easily when you add one, two or no sidebar content in those regions, the grid layout adapts dynamically depending on the block content — We will create a simple module that will extend twig. — We will create a twig extension that will be able to print any block directly from the twig file
  • 6. Let’s Get Down To Business Monkey Business
  • 7. Twig Blocks Definition 7 Blocks are used for inheritance and act as placeholders and replacements at the same time. - Twig Documentation “ — Enclose code in blocks in main template file — Code inside the block tags can be overridden by extend theme files — Blocks can exist inside other blocks
  • 8. Twig Extends & Variables Pass Definition 8 Twig extends can be used to extend a template from another one. - Twig Documentation “ — Start by declaring the file you are extending — Override anything you like by using blocks — You can also pass variables to the main template
  • 9. Twig Extends & Variables Pass If you don’t use extend… 9 Main theme file Theme override
  • 10. Twig Conditionals Dynamic Theming Is Here 10 The if statement in Twig is comparable with the if statements of PHP. In the simplest form you can use it to test if an expression evaluates to true - Twig Documentation “ — Simple condition that checks if there are blocks in regions sidebar right or sidebar left — If there are blocks and statements are true it dynamically changes the markup classes — Control the layout directly from the back end block layout page
  • 11. Layout Building Using Conditionals Content Type Creation 11 — Choose Layout at content creation level (on content type) — Variables are set depending on the selected option — Conditions change the layout as needed
  • 12. Twig Extend & Filter Display any block anywhere 12 Register the extension as a service blockTwigExtension.php
  • 13. Demo Time The time you’ve been waiting for

Hinweis der Redaktion

  1. Generally it’s a best practice to put all your code inside blocks so it is easier to override later on with extends. Everything inside a block statement can be overriden. Blocks can also exist inside other blocks
  2. Extending a template is easy. You first declare the template filename you are extending. Then you just add the block or blocks that you want to override and your code inside. You can also pass variables from the child theme to the parent theme.
  3. This is what you have to do to have the same effect as the previous file if you don’t use twig extend. You basically have to code the whole file and make the changes you want on it.
  4. Twig if else statements. The demo contains a simple if else check for certain blocks in the theme layout regions and if present it gives specific predefined classes so it can adjust the layout automagically.
  5. In the content creation level the editor can choose from a predefined dropdown menu the front page layout. Variables and conditionals are then checked and they create the desired layout.