Write Up: Twig theme sprint @ DrupalCon Munich

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
jenlampton's picture

During DrupalCon Munich we had two sessions devoted to Twig.

The first was a high-level session on twig geared towards front-end developers: A designer-friendly theme system in Drupal 8?. The second was a core conversation geared to hearing more from front end developers about what they wanted from the theme layer: A new theme layer for Drupal 8

If you missed either one of these sessions I would recommend watching the videos (links above) to get caught up.

After getting an overwhelming consensus from both the above sessions that Drupal 8 should commit to using Twig for the theme layer, we had a really great sprint on Twig at DrupalCon Munich.

Only local images are allowed.
Photo thanks to Amazee Labs

We had one table of engineers working on how to get the twig rendering engine dealing with Render Arrays by turning them into objects, while at the same time trying to merge our working sandbox back in to Drupal 8 HEAD. It would be great if we could get a volunteer who'd be willing to rebase for us once a week or so while we're making progress on the sandbox. If this sounds like it's up your alley, contact me!

We had three full tables of committed front end developers helping us convert the existing template files and theme functions into twig, and at the same time studying the markup produced by core to identify places where theme functions (now template files) could be consolidated.

For anyone who wants to get involved, there are plenty of theme functions that still need to be converted! Please take a look at our spreadsheet and if you see something you'd like to convert, follow our step-by-step instructions on how to convert to twig.

In addition to the four tables of hard-working sprinters, we also had a whiteboard with a crowd of 5 to 15 people chattering about what we should be doing with twig, pretty much all day long (thank you everyone who participated in the debates and made yourselves hoarse!).

We came to some great conclusions about how twig can work with both the existing render and preprocess, paving the path to getting twig working for our first patch.

We also decided where our markup should live in core (a 'templates' directory inside every module that needs to provide it's own markup). Another thing we can write patches against now. (see http://drupal.org/node/1760530)

We also discussed and decided on how we should be using Twig template inheritance in core (we won't use it in core template files, but we can show an example of how it could be done in core themes).

Unfortunately, using twig template inheritance will create an namespace conflict with 'block' meaning one thing in Twig and another in Drupal, which prompts us to change the name of blocks.

On Thursday Aug 30th, at 7:30pm GMT we are all going to meet again in IRC to grab the link to a Google Plus Hangout where we can discuss which template files should be consolidated, and which template files should stay. The idea is to create a more streamlined set of base template files for core, more closely reflecting Jacne's concept of standard components. Please read her blog post before we meet, I immagine we'll start there.

As soon as we make some decisions on which template files to keep and which to throw out, we can start paring down our theme system (with patches against core! This does not need to wait for Twig to get in).

Then we begin writing preprocess functions to handle the variables for the template files that will stay - cleaning up the templates and riding them of unnecessary PHP logic, moving all we can up one level to the preprocess layer.

Another thing we can work on right away (before Twig gets in) is the removal of the process layer. Now that attributes are being handled smartly, we don't need that layer to flatten arrays of classes. We'll also need to move all the stuff that gets done there up to the preprocess layer, and that can be done now with patches agains core (any volunteers?)

Comments

Nice writeup Jen! Was a great

aburrows's picture

Nice writeup Jen! Was a great achievement getting it to work, despite a few teething issues and a few user_access() bugs.. But looking forward to our group IRC meeting and pushing this forward!

We're still sprinting....

pixelmord's picture

I'm continuing to work on the files and functions in my sandbox and there have been other contributions as well since the sprint here on Friday.

And also we have to test the files and review the markup, because during the sprint we worked more or less blind, because the twig engine was not operational. At the end of the sprint we merged a patched version back in and now the code runs for testing the created files.

Right now there are still some errors and notices thrown, but only some originate in our twig templates.
Not all the twig templates that will be replacements for theme functions are registered in hook_theme, so don't worry if one or the other file does not get called, also here will be still work to be done..

@Jen: we need to discuss where (which queues) we post the issues
* that are about how to use twig together with drupal (drupal core queue?)
* regarding the theme engine ( chx sandbox?)
* regarding possible simplifications like consolidating template files (my sandbox or core?)
* the markup created within the new twig templates (my sandbox or core?)

It was great working with all contributors during the sprint and I'm really looking forward to see this happening. #themer-experience FTW

****************
wunderkraut - Da wächst etwas..... www.wunderkraut.com

Let's not worry too much

jenlampton's picture

Let's not worry too much about the errors yet - hopefully after our meeting on Thursday we'll be able to eliminate a lot of those new files, and we won't have to worry about cleaning up the errors :)

Issues about twig with Drupal should be posted in the chx issue queue

Issues regarding the theme engine should be posted in the chx issue queue

Let's not open any issues about simplification until we're sure - and post them in the core issue queue. I've been using both tags 'theme system cleanup' and 'Twig'

Issues about the markup created within the new twig templates should probably stay in your sandbox.

update: the chx sandbox is no longer in use. Please use the pixelmord sandbox

So we committed our twig

aburrows's picture

So we committed our twig changes (twig engine) to chx's branch, this included Drupal 8 latest dev core and the amends we did to get twig to work. I agree that we need to work out the best place for this to go, as with d8 core changing all the time, we need to keep it in sync as much as we can.