Twig and the new theme layer in Drupal 8

Last updated on
6 October 2020


Regular meetings

We are organizing our effort via several channels:

  • Google hangout every 2 weeks: We'll put together an agenda and talk about progress and next steps. For the dates and times see the Google calendar (below) or check the topic in #drupal-twig on IRC.
  • Drupal Twig calendar: For Google hangout times, upcoming sprints, etc.: Subscribe to iCalendar feed or add ubk01l2m902412nhi4ef2hjn20@group.calendar.google.com to Google Calendar
  • Chat: #drupal-twig on Freenode. Come join the discussion to collaborate or ask questions. We hold unofficial office hours here on Thursdays before and after the call.

    If you'd like to get involved but aren't sure where to start, attending core mentoring is a great first step. Talk to a mentor and mention that you want to help with Twig and the theme layer in Drupal 8.



Essential Resources

Here are some essential resources for helping us with the move to Twig:



Roadmap

Current plan for cleaning up the theme system.

  1. Update core to use two different theme engines, & fallback to PHPTemplate:
  2. Add simple example of Twig to core:
  3. Convert PHPtemplate files to Twig & use Twig as the default:
  4. Must-have's for Drupal 8

  5. Nice-to-have for Drupal 8

  6. Drupal 8 - NEW markup "nice-to-haves" (lowest priority)



Issue tags & Documentation

See the following tags for core issues related to Twig and revising Drupal's theme system.



Code sprints

Date Sprint
Current and upcoming sprints
Sept 27 - October 5, 2014 DrupalCon Amsterdam
November 6-9, 2014 BADCamp
Past sprints Docs
August 29-31, 2014 Frontend United
June 2-6, 2014 DrupalCon Austin
March 23-29, 2014 NYC Camp
April 12-13, 2014 DrupalCamp Frankfurt Days
Mar 27-30, 2014 with sprints @ Palantir before MidCamp
Mar 24-30, 2014 Drupal Developer Days
March 15-16, 2014 DrupalCamp Stockholm
March 01-02, 2014 DrupalCamp London
Oct 24-27, 2013 BADCamp
Oct 5-6, 2013 PNWDS
Sept 23-27, 2013 DrupalCon Prague
July 25-27, 2013 Midwest Developer Summit
July 18-20, 2013 Twin Cities Drupal Camp
July 12-15, 2013 NYC Camp
June 2nd, 2013 CodeSprint UA 2013
May 24th, 2013 DrupalCon Portland
May 3rd, 2013 Twig Sprint (Stanford University, & online)
Apr 20th, 2013 Twig Sprint (Charlotte, NC)
Apr 19th, 2013 Twig Sprint (online)
Mar 22nd, 2013 Twig Sprint (online)
March 9th & 10th, 2013 Drupal Sprint Weekend
Feb 9th, 2013 DrupalCon Sydney
Jan 26th, 2013 SandCamp
Nov 24-25, 2012 DrupalCamp North West Summary
Nov 16-17, 2012 Drupal 8 Code Sprint in Vancouver
Nov 1-4, 2012 BADCamp Summary
Oct 26-28, 2012 DrupalHagen
Sept 29, 2012 DrupalCamp London
Sept 8-9, 2012 Drupal Night, Ukraine
Aug 20-24, 2012 DrupalCon Munich Summary Resources
July 21-22, 2012 NYC Camp Summary
May 20, 2012 Twin Cities Drupal Camp Summary Resources
April 20-22, 2012 Chapter Three Summary Resources


Principles: Waypoints to guide us

At the BADCamp 2012 theme sprint, we outlined some core principles to guide our work for the D8 theme layer.

Start with nothing
Core default markup should strive for semantic simplicity, with few HTML elements, added only as needed
Build from use cases
Don't assume you know what people want or add features based on "What-if?" Think about the 90% of use cases.
Provide tools
Give front-end experts a way to achieve specific goals; goals that apply to the remaining 10% of use cases. Keep in mind that complex problems may require complex solutions.
Consolidate
"Your markup is not special." Don't make something new. Work toward common theme functions that modules leverage (i.e. a Theme Component Library).
Visibility
You should be able to see what's going on in a template without reading docs. Twig provides a lot of this by virtue of its syntax (it looks like HTML). Form follows function.
Consistency
Do the same things everywhere, follow patterns. Use similar variable names across templates if they represent similar things.
Don't dumb it down
Complexity should be reduced but not obscured. Themers *can* understand template logic and loops. When complexity does happen, use comments to explain why.
Organization should be driven by meaning and semantics over technical convenience
Consider what an element means rather than how it structurally appears. For example: theme_item_list() came about from a developer's perspective: OL and UL markup is nearly structurally the same, so providing a single function with the type argument came about from a code efficiency standpoint. However, from a semantic HTML perspective, we do not use a singular 'list' element with an attribute to indicate whether it is ordered or unordered, we have two different elements. Semantically, OL and UL represent different information. Therefore, we should provide a separate templates for OL and UL, even though they contain nearly identical markup.
Related to this principle (and the principle of Visibility), names and locations of templates should be self-evident. Consider where a newcomer might expect to override markup. Example: Someone looking to override a menu isn't going to look for a item_list template, even if a menu is structurally identical. So we should not simply have a menu use an item list, nor should we simply include an item list from a menu template. Themers want to see markup in templates, not abstraction.


Tell your friends

Send people to this page using this link: http://lb.cm/twig

Help improve this page

Page status: No known problems

You can: