[Srijan Wednesday Webinars] Drupal 8: Frontend for Backenders

  • Published on
    15-Jul-2015

  • View
    377

  • Download
    1

Transcript

Drupal 8Frontend (forbackenders)01.04.2015 Lauri Eskola / @laurii1@srijan #SrijanWWLauri EskolaI live in FinlandFront and Back End DeveloperMostly working on Core issuesrelated to Theme system on theBack End sideWorking for DruidI do actually like cold (andsauna)@srijan #SrijanWW@lauriii@srijan #SrijanWW@laurii1@srijan #SrijanWWTopics1. Theme system2. Twig3. Autoescape4. Demo@srijan #SrijanWWChanges related to themelayer@srijan #SrijanWWDrupal 7 theme layer - WTF?@srijan #SrijanWWTemplate process layer ...is gone!hook_page_alter ...is gone!@srijan #SrijanWW@srijan #SrijanWWTheme functions...are being converted to Twig templates..@srijan #SrijanWWGoodbye theme(), hello render arraysDrupal 7@srijan #SrijanWWDrupal 8 theme layer - FTW!@srijan #SrijanWWTheme suggestion hooks@srijan #SrijanWWTheme suggestion hooksDrupal 7Preprocess hooks & missing processfunctions@srijan #SrijanWWAttributes AttributesTwigNot like this: @srijan #SrijanWWAttributes {% set classes [ 'a-lot-of', 'classes-needed', 'for-this-element' ] %} TwigCrash course for backenders@srijan #SrijanWWTwig magic{{ sandwich.cheese }}Same in PHP // Array key. $sandwich['cheese']; // Object property. $sandwich->cheese; // Also works for magic get (provided you implement magic isset). $sandwich->__isset('cheese'); && $sandwich->__get('cheese'); // Object method. $sandwich->cheese(); // Object get method convention. $sandwich->getCheese(); // Object is method convention. $sandwich->isCheese(); // Method doesn't exist/dynamic method. $sandwich->__call('cheese'); @srijan #SrijanWWPrint what you want, when you wantDrupal 7Twig filtersMeant to manipulate content. Simply takes the first parameter from avariable or inline string and returns it in different format.Example {% set name = 'Lauri' %} {# Print varibale using lenght filter. #} {{ name|length }} Returns 5 @srijan #SrijanWWTwig functionsMore viable functions with multiple parameters meant to create simplefront-end logic {{ dump() }} @srijan #SrijanWWThis magic is built in TwigHow ever I'm going to show you how to add these by your self!@srijan #SrijanWWAdding Twig filters Adding Twig filters {% set variable = 'my text' %} {{ variable|trim_string(2) }} my @srijan #SrijanWWAdding Twig functions Example:https://github.com/lauriii/trim-string@srijan #SrijanWW"I don't want to learn anythingnew!""I don't like Twig!"@srijan #SrijanWWSolution! # engine: phptemplate themename.info.yml@srijan #SrijanWWAutoescape@srijan #SrijanWW@srijan #SrijanWWContext-Aware Auto-EscapingBasic idea: everytime variable goes to template run appropriate escapingfunction!@srijan #SrijanWWDifferent Escape functions How it works? Sandwiches demo!https://github.com/DrupalTwig/sandwich@srijan #SrijanWWWant to help?Isn't this stuff awesome?We can still make it better! Join your localsprints!@srijan #SrijanWWTake this conversation online by tweeting using the hashtag #SrijanWWThank you!Lauri Eskola / @laurii1@srijan #SrijanWW