SlideShare ist ein Scribd-Unternehmen logo
1 von 29
DRUPAL 8 版型開發變⾰革
Chris Wu
TIME TO START WITH
DRUPAL 8
CODING
STANDARD
SMACSS & BEM
SMACSS - Scalable and Modular Architecture for CSS
Base
Layout
Module
State
Theme
BEM
.block__element--modifier
Block
Element
Modifier
BLOCK	
  	
  node	
  
	
  	
  __	
  ELEMENT	
  	
  title	
  	
  
	
  	
  __	
  ELEMENT	
  	
  content	
  
	
  	
  BLOCK	
  	
  field	
  
	
  	
  	
  	
  __	
  ELEMENT	
  label	
  
	
  	
  	
  	
  __	
  ELEMENT	
  items	
  
	
  	
  	
  	
  	
  	
  	
  -­‐-­‐	
  MODIFIER	
  	
  active	
  	
  	
  
BEM
NO CLASS
In Drupal Core
CLASSY
The New Core Theme
THEME LAYER
Classy
SparkBartik Seven
Drupal Core
THEME
structure changed
[theme].info.yml
[theme].theme
THEME - STRUCTURE CHANGED
/theme
[theme].libraries.yml
[theme].breakpoin.yml
name:	
  Foo	
  
type:	
  theme	
  
base	
  theme:	
  classy	
  
description:	
  'Foo	
  bar	
  theme'	
  
core:	
  8.x	
  
libraries:	
  
	
  	
  -­‐	
  foo/global-­‐styling	
  
	
  	
  -­‐	
  foo/bar	
  
regions:	
  
	
  	
  header:	
  Header	
  
	
  	
  primary_menu:	
  'Primary	
  menu'	
  
	
  	
  secondary_menu:	
  'Secondary	
  menu'
.INFO.YML
TEMPLATING
Template Suggestion
Pattern: node--[type|nodeid].tpl.php
1 node--nodeid.tpl.php
2 node--type.tpl.php
3 node.tpl.php
Pattern: node--[type|nodeid].html.twig
1 node--nodeid.html.twig
2 node--type.html.twig
3 node.html.twig
標題⽂文字
TWIG
no more theme_() and *.tpl.php
• 版型檔案不允許直接執⾏行	
  PHP	
  ,讓版型更為安全。	
  
• 版型開發者不必再學	
  PHP	
  
• 預設輸出時皆會	
  escape	
  ,減少	
  XSS	
  的可能性	
  
//	
  This	
  really	
  shouldn't	
  be	
  allowed	
  to	
  work,	
  and	
  it	
  won't	
  in	
  D8.	
  
<?php db_query('DROP TABLE {users}'); ?>
FROM PHPTEMPLATE TO TWIG
{{	
  }}	
  "say"	
  something	
  
{%	
  %}	
  "do"	
  something	
  
{#	
  #}	
  "write"	
  something
TWIG 101
– Drupal 8
{{	
  page.sidebar	
  }}	
  
{{	
  page['#type']	
  }}
Here are some example of filters from the Twig
engine.
{{ 'drupal' | length }} //return: 6
{{ 'drupal' | upper }} //return: DRUPAL
{{ 'drupal is awesome' | title }} //return: Drupal Is Awesome!
{{ '<a href="#">drupal is awesome!</a>'| striptags | capitalize }}
//return: Drupal is awesome!
FILTER
Drupal offers some additional filters.
Translation filters
PHP:	
  
<?php t('Content type'); ?>
TWIG:	
  
{{ 'Content type' | t }} //return: 內容類型
<a href="{{url('<front>')}}">{{'Home'|t}}</a> //return: ⾸首⾴頁
FILTER
{% for item in items %}
{% if not loop.last %}
<li{{ item.attributes }}>
{{ item.content }}
</li>
{% endif %}
{% endfor %}
DO SOMETHING
{%
set classes = [
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
]
%}
<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
{% block content %}
<div{{ content_attributes.addClass('content') }}>
{{ content }}
</div>
{% endblock %}
</div>
{% BLOCK %}
{# block.html.twig #}
{# block--system-powered-by-block.html.twig #}
{% extends "block.html.twig" %}
{% block content %}
<div{{content_attributes.addClass('content')}}>
{{ content }}
</div>
{% endblock %}
{% BLOCK %}
#sites/default/settings.php:	
  	
  
$settings['container_yamls'][]	
  =	
  DRUPAL_ROOT.'/sites/development.services.yml';	
  
$settings['cache']['bins']['render']	
  =	
  'cache.backend.null';	
  
#sites/development.services.yml:	
  
parameters:	
  
	
  	
  twig.config:	
  
	
  	
  	
  	
  debug:	
  true
ENABLE DEBUGGING
PHP:	
  
<?php	
  var_dump();	
  ?>	
  
TWIG:	
  
{{	
  dump()	
  }}
DUMP VARIABLE
PHP	
  with	
  Devel	
  module:	
  
<?php	
  dpm();	
  ?>	
  
TWIG	
  with	
  Devel	
  +	
  Kint:	
  
{{	
  kint()	
  }}
BETTER DUMP
• Template Naming Convention: https://www.drupal.org/node/2354645
• The Drupal 8 Theming guide: http://d8.sqndr.com/new-theming-layer/README.html
• Deep dive anatomy drupal 8 theme: http://x-team.com/2015/04/deep-dive-anatomy-drupal-8-theming/
• D8Theming (with debug tut): http://savaslabs.com/2015/06/10/d8-theming-basics.html
REFERENCES
CHRIS WU
Cheers!
fb.me/amouro
@amourow

Weitere ähnliche Inhalte

Was ist angesagt?

Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
Tammy Hart
 
Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!
Herman Peeren
 

Was ist angesagt? (20)

Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
Drupal 7 — Circle theme
Drupal 7 — Circle themeDrupal 7 — Circle theme
Drupal 7 — Circle theme
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019
 
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
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
 
Dc kyiv2010 jun_08
Dc kyiv2010 jun_08Dc kyiv2010 jun_08
Dc kyiv2010 jun_08
 
Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to theming
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPress
 
Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
Apostrophe
ApostropheApostrophe
Apostrophe
 
Extending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockExtending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh Pollock
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Plugins
 
The Render API in Drupal 7
The Render API in Drupal 7The Render API in Drupal 7
The Render API in Drupal 7
 
Drupal Theme Development
Drupal Theme DevelopmentDrupal Theme Development
Drupal Theme Development
 

Andere mochten auch

индивидуальная работа с детьми в подготовительной группе
индивидуальная работа с детьми в подготовительной группеиндивидуальная работа с детьми в подготовительной группе
индивидуальная работа с детьми в подготовительной группе
virtualtaganrog
 
Шкатулка качественных задач
Шкатулка качественных задачШкатулка качественных задач
Шкатулка качественных задач
sveta7940
 
Внеклассное мероприятие"Открытая лаборатория"
Внеклассное мероприятие"Открытая лаборатория"Внеклассное мероприятие"Открытая лаборатория"
Внеклассное мероприятие"Открытая лаборатория"
sveta7940
 

Andere mochten auch (16)

план мероприятий по году литературы мбдоу 231
план мероприятий по году литературы  мбдоу 231план мероприятий по году литературы  мбдоу 231
план мероприятий по году литературы мбдоу 231
 
2017_03_20 СКРЕБЕЦЬ Ю.Ю. - заступник головного лікаря з хірургічної служби
2017_03_20 СКРЕБЕЦЬ Ю.Ю. - заступник головного лікаря з хірургічної служби2017_03_20 СКРЕБЕЦЬ Ю.Ю. - заступник головного лікаря з хірургічної служби
2017_03_20 СКРЕБЕЦЬ Ю.Ю. - заступник головного лікаря з хірургічної служби
 
индивидуальная работа с детьми в подготовительной группе
индивидуальная работа с детьми в подготовительной группеиндивидуальная работа с детьми в подготовительной группе
индивидуальная работа с детьми в подготовительной группе
 
50 jawapan ulasan
50 jawapan ulasan50 jawapan ulasan
50 jawapan ulasan
 
Mi autografía artística
Mi autografía artísticaMi autografía artística
Mi autografía artística
 
Шкатулка качественных задач
Шкатулка качественных задачШкатулка качественных задач
Шкатулка качественных задач
 
Внеклассное мероприятие"Открытая лаборатория"
Внеклассное мероприятие"Открытая лаборатория"Внеклассное мероприятие"Открытая лаборатория"
Внеклассное мероприятие"Открытая лаборатория"
 
Unit 4. natural sciences.
Unit 4. natural sciences.Unit 4. natural sciences.
Unit 4. natural sciences.
 
Theories career development counseling
Theories career development counselingTheories career development counseling
Theories career development counseling
 
2. toxicología capítulo 2
2. toxicología   capítulo 22. toxicología   capítulo 2
2. toxicología capítulo 2
 
A doctor's journey from war-torn Baghdad to Norfolk
A doctor's journey from war-torn Baghdad to NorfolkA doctor's journey from war-torn Baghdad to Norfolk
A doctor's journey from war-torn Baghdad to Norfolk
 
Digital media market_brief_2017_03
Digital media market_brief_2017_03Digital media market_brief_2017_03
Digital media market_brief_2017_03
 
FabZat Publisher Presentation 2016
FabZat Publisher Presentation 2016FabZat Publisher Presentation 2016
FabZat Publisher Presentation 2016
 
Searching for reliable business information: free versus fee
Searching for reliable business information: free versus feeSearching for reliable business information: free versus fee
Searching for reliable business information: free versus fee
 
1. perspectivas teóricas aprendizaje conductual, cognitiva, TAS de Bandura
1. perspectivas teóricas aprendizaje conductual, cognitiva, TAS de Bandura1. perspectivas teóricas aprendizaje conductual, cognitiva, TAS de Bandura
1. perspectivas teóricas aprendizaje conductual, cognitiva, TAS de Bandura
 
How to run more creative events that add value.
How to run more creative events that add value.How to run more creative events that add value.
How to run more creative events that add value.
 

Ähnlich wie Drupal 8 版型開發變革

Theming tips and tricks
Theming tips and tricksTheming tips and tricks
Theming tips and tricks
aaroncouch
 
Drupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton ShubkinDrupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton Shubkin
ADCI Solutions
 

Ähnlich wie Drupal 8 版型開發變革 (20)

Drupal theming
Drupal themingDrupal theming
Drupal theming
 
Building Drupal 6 Theme
Building Drupal 6 ThemeBuilding Drupal 6 Theme
Building Drupal 6 Theme
 
Drupal theme development
Drupal theme developmentDrupal theme development
Drupal theme development
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend development
 
The Flexibility of Drupal 8 | DCNLights 2017
The Flexibility of Drupal 8 | DCNLights 2017The Flexibility of Drupal 8 | DCNLights 2017
The Flexibility of Drupal 8 | DCNLights 2017
 
Theming tips and tricks
Theming tips and tricksTheming tips and tricks
Theming tips and tricks
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
 
Drupal
DrupalDrupal
Drupal
 
Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)Changes to Drupal Themes in version 7 (part 1)
Changes to Drupal Themes in version 7 (part 1)
 
Drupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton ShubkinDrupal 8: What's new? Anton Shubkin
Drupal 8: What's new? Anton Shubkin
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
 
Drupal Themes
Drupal ThemesDrupal Themes
Drupal Themes
 
Drupal7 themeing changes and inheritence
Drupal7 themeing changes and inheritenceDrupal7 themeing changes and inheritence
Drupal7 themeing changes and inheritence
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
Drupal 8 Every Day: An Intro to Developing With Drupal 8
Drupal 8 Every Day: An Intro to Developing With Drupal 8Drupal 8 Every Day: An Intro to Developing With Drupal 8
Drupal 8 Every Day: An Intro to Developing With Drupal 8
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
 
Demystifying drupal 7 theming
Demystifying drupal 7 themingDemystifying drupal 7 theming
Demystifying drupal 7 theming
 
Theme Kickstart
Theme KickstartTheme Kickstart
Theme Kickstart
 

Mehr von Chris Wu

DrupalTaiwan.org 社群簡介
DrupalTaiwan.org 社群簡介DrupalTaiwan.org 社群簡介
DrupalTaiwan.org 社群簡介
Chris Wu
 
Drupal 版型設計 - 瞭解版型程式
Drupal 版型設計 - 瞭解版型程式Drupal 版型設計 - 瞭解版型程式
Drupal 版型設計 - 瞭解版型程式
Chris Wu
 

Mehr von Chris Wu (9)

Effective Designer - 有效率的設計師
Effective Designer - 有效率的設計師Effective Designer - 有效率的設計師
Effective Designer - 有效率的設計師
 
Building E-Commerce Content Marketing Site for Fashion Industry - Drupal Camp...
Building E-Commerce Content Marketing Site for Fashion Industry - Drupal Camp...Building E-Commerce Content Marketing Site for Fashion Industry - Drupal Camp...
Building E-Commerce Content Marketing Site for Fashion Industry - Drupal Camp...
 
MRT Express 極速北捷(UI/UX Designers' Night)
MRT Express 極速北捷(UI/UX Designers' Night)MRT Express 極速北捷(UI/UX Designers' Night)
MRT Express 極速北捷(UI/UX Designers' Night)
 
從技術角度看 RWD - Technical Approaches to RWD
從技術角度看 RWD - Technical Approaches to RWD從技術角度看 RWD - Technical Approaches to RWD
從技術角度看 RWD - Technical Approaches to RWD
 
Responsive design on drupal
Responsive design on drupalResponsive design on drupal
Responsive design on drupal
 
那些年,我們一起搞的金流
那些年,我們一起搞的金流那些年,我們一起搞的金流
那些年,我們一起搞的金流
 
DrupalTaiwan.org 社群簡介
DrupalTaiwan.org 社群簡介DrupalTaiwan.org 社群簡介
DrupalTaiwan.org 社群簡介
 
Drupalcamp Taipei 2012 說明會
Drupalcamp Taipei 2012 說明會Drupalcamp Taipei 2012 說明會
Drupalcamp Taipei 2012 說明會
 
Drupal 版型設計 - 瞭解版型程式
Drupal 版型設計 - 瞭解版型程式Drupal 版型設計 - 瞭解版型程式
Drupal 版型設計 - 瞭解版型程式
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Drupal 8 版型開發變革

  • 2. TIME TO START WITH DRUPAL 8
  • 4. SMACSS - Scalable and Modular Architecture for CSS Base Layout Module State Theme
  • 6. BLOCK    node      __  ELEMENT    title        __  ELEMENT    content      BLOCK    field          __  ELEMENT  label          __  ELEMENT  items                -­‐-­‐  MODIFIER    active       BEM
  • 11. [theme].info.yml [theme].theme THEME - STRUCTURE CHANGED /theme [theme].libraries.yml [theme].breakpoin.yml
  • 12. name:  Foo   type:  theme   base  theme:  classy   description:  'Foo  bar  theme'   core:  8.x   libraries:      -­‐  foo/global-­‐styling      -­‐  foo/bar   regions:      header:  Header      primary_menu:  'Primary  menu'      secondary_menu:  'Secondary  menu' .INFO.YML
  • 14. Template Suggestion Pattern: node--[type|nodeid].tpl.php 1 node--nodeid.tpl.php 2 node--type.tpl.php 3 node.tpl.php Pattern: node--[type|nodeid].html.twig 1 node--nodeid.html.twig 2 node--type.html.twig 3 node.html.twig 標題⽂文字
  • 15. TWIG no more theme_() and *.tpl.php
  • 16. • 版型檔案不允許直接執⾏行  PHP  ,讓版型更為安全。   • 版型開發者不必再學  PHP   • 預設輸出時皆會  escape  ,減少  XSS  的可能性   //  This  really  shouldn't  be  allowed  to  work,  and  it  won't  in  D8.   <?php db_query('DROP TABLE {users}'); ?> FROM PHPTEMPLATE TO TWIG
  • 17. {{  }}  "say"  something   {%  %}  "do"  something   {#  #}  "write"  something TWIG 101
  • 18. – Drupal 8 {{  page.sidebar  }}   {{  page['#type']  }}
  • 19. Here are some example of filters from the Twig engine. {{ 'drupal' | length }} //return: 6 {{ 'drupal' | upper }} //return: DRUPAL {{ 'drupal is awesome' | title }} //return: Drupal Is Awesome! {{ '<a href="#">drupal is awesome!</a>'| striptags | capitalize }} //return: Drupal is awesome! FILTER
  • 20. Drupal offers some additional filters. Translation filters PHP:   <?php t('Content type'); ?> TWIG:   {{ 'Content type' | t }} //return: 內容類型 <a href="{{url('<front>')}}">{{'Home'|t}}</a> //return: ⾸首⾴頁 FILTER
  • 21. {% for item in items %} {% if not loop.last %} <li{{ item.attributes }}> {{ item.content }} </li> {% endif %} {% endfor %} DO SOMETHING
  • 22. {% set classes = [ 'block', 'block-' ~ configuration.provider|clean_class, 'block-' ~ plugin_id|clean_class, ] %} <div{{ attributes.addClass(classes) }}> {{ title_prefix }} {% if label %} <h2{{ title_attributes }}>{{ label }}</h2> {% endif %} {{ title_suffix }} {% block content %} <div{{ content_attributes.addClass('content') }}> {{ content }} </div> {% endblock %} </div> {% BLOCK %} {# block.html.twig #}
  • 23. {# block--system-powered-by-block.html.twig #} {% extends "block.html.twig" %} {% block content %} <div{{content_attributes.addClass('content')}}> {{ content }} </div> {% endblock %} {% BLOCK %}
  • 24.
  • 25. #sites/default/settings.php:     $settings['container_yamls'][]  =  DRUPAL_ROOT.'/sites/development.services.yml';   $settings['cache']['bins']['render']  =  'cache.backend.null';   #sites/development.services.yml:   parameters:      twig.config:          debug:  true ENABLE DEBUGGING
  • 26. PHP:   <?php  var_dump();  ?>   TWIG:   {{  dump()  }} DUMP VARIABLE
  • 27. PHP  with  Devel  module:   <?php  dpm();  ?>   TWIG  with  Devel  +  Kint:   {{  kint()  }} BETTER DUMP
  • 28. • Template Naming Convention: https://www.drupal.org/node/2354645 • The Drupal 8 Theming guide: http://d8.sqndr.com/new-theming-layer/README.html • Deep dive anatomy drupal 8 theme: http://x-team.com/2015/04/deep-dive-anatomy-drupal-8-theming/ • D8Theming (with debug tut): http://savaslabs.com/2015/06/10/d8-theming-basics.html REFERENCES