forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
d8.html
executable file
·958 lines (827 loc) · 34.7 KB
/
d8.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Drupal 8 Theming Crash Course</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="plugin/prism/prism.css">
<link rel="stylesheet" href="plugin/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" href="css/theme/wes-light.css" id="theme">
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section class="center">
<p class="small" style="position: relative; top: -6em;"><strong>Pro-tip:</strong> Press <span style="display: inline-block; padding: .2em .6em; border: 1px solid #777; border-radius: .3em; background: #fff; box-shadow: 0 1px 0 #555, 0 2px 0 #555, 0 3px 0 #555, 0 4px 0 #555; position: relative; top: -.1em;">space bar</span> to progress and it won't skip any slides</p>
<h1 id="drupal-8-theming">Drupal 8 Theming</h1>
<p>A thorough crash course</p>
</section>
<section style="text-align: left;">
<h2 id="who-am-i" style="font-weight: 200">About Me...</h2>
<img src="assets/d8/me.jpg" alt="" style="width: 35%; float: right;">
<div style="box-sizing: border-box; width: calc(65% - 0.6em);">
<h3 id="wes-ruvalcaba">Wes Ruvalcaba</h3>
<ul>
<li>Front End Dev at Lullabot</li>
<li>Worked with Drupal since version 6</li>
<li>Markup Snob, CSS & Sass Dork</li>
<li>Write custom code, more than repurpose existing</li>
</ul>
</div>
<p style="margin-top: 1em;"><a href="https://twitter.com/wesruv"><i class="fa fa-twitter" style="font-size: 2em; line-height: .5em; padding: 0 .2em 0 0; transform: translateY(.15em);"></i>@wesruv</a></p>
</section>
<section data-background-color="#fff">
<img src="assets/d8/lullabot-slide.jpg" alt="Lullabot" />
</section>
<section>
<h1 id="what-we-ll-go-over">What We'll Go Over</h1>
<ul>
<li>File Organization</li>
<li>Very Lean Core Markup</li>
<li>CEM Class Syntax</li>
<li>Twig</li>
<li>YML and Beefed up Config Functionality</li>
<li>and more!!!</li>
</ul>
</section>
<section class="center">
<h1 id="file-organization">File Organization</h1>
</section>
<section>
<h2 id="core-is-in-it-s-own-folder">Core is in its own folder</h2>
<ul class="file-list">
<li><i class="fa fa-drupal" style="color: #0c76ab; font-size: 1.5em; margin-top: -.3em"></i> <span class="element-invisible">Drupal</span>
<ul>
<li style="background: #ffec99"><strong>core</strong>
<ul>
<li>assets</li>
<li>config</li>
<li>...</li>
</ul>
</li>
<li>modules</li>
<li>profiles</li>
<li>sites</li>
<li>themes</li>
</ul>
</li>
</ul>
</section>
<section>
<h3 id="your-stuff-is-in-the-root">Your stuff is easier to get to!</h3>
<ul class="file-list">
<li><i class="fa fa-drupal" style="color: #0c76ab; font-size: 1.5em; margin-top: -.3em"></i> <span class="element-invisible">Drupal</span>
<ul>
<li>core</li>
<li>modules
<ul>
<li style="background: #ffec99">mymodule</li>
</ul>
</li>
<li>profiles</li>
<li>sites</li>
<li>themes
<ul>
<li style="background: #ffec99">mytheme</li>
</ul>
</li>
</ul>
</li>
</ul>
</section>
<section>
<h2 id="template-php-has-a-new-name">Template.php has a new name</h2>
<div style="font-size: 1.4em; margin: 1em 0 1.5em">
<p><i class="fa fa-file"></i> <s>template.php</s></p>
<p><i class="fa fa-long-arrow-down" style="font-size: 2em;"></i></p>
<p><i class="fa fa-file"></i> mytheme.theme</p>
</div>
<p>The theme's name with a ".theme" extension.</p>
<p class="small" style="margin-top: 2em"><a href="https://www.drupal.org/node/2349803">drupal.org/node/2349803</a></p>
</section>
<section>
<h2 id="themename-info-is-now-themename-info-yaml">The Info File has a new name</h2>
<div style="font-size: 1.4em; margin: 1em 0 1.5em">
<p><i class="fa fa-file"></i> <s>mytheme.info</s></p>
<p><i class="fa fa-long-arrow-down" style="font-size: 2em;"></i></p>
<p><i class="fa fa-file"></i> mytheme.info.yml</p>
</div>
<p>The theme's name with a ".info.yml" extension.</p>
<p class="small"><a href="https://www.drupal.org/node/2349803">drupal.org/node/2349803</a></p>
</section>
<section class="center">
<h1 id="cem-class-syntax">CEM Class Syntax</h1>
<p>aka (BEM)</p>
<p class="small"><a href="https://www.drupal.org/coding-standards/css/architecture">drupal.org/coding-standards/css/architecture</a></p>
</section>
<section>
<section>
<h2 id="the-rules">The Rules</h2>
<ul>
<li><strong>We use classes</strong>; ID's are the devil</li>
<li><strong>Components</strong> (The C in CEM) are a chunk of markup that works together;
<br>e.g. a menu, a teaser, a who's online widget, a social share widget, an article.</li>
<li>An <strong>element</strong> (the E in CEM) is a piece of the whole.
<br>e.g. a title, some text, an image, call to action link.</li>
<li>A <strong>modifier</strong> is a suffix that can denote a slightly different version of a Component or Element</li>
</ul>
</section>
<section>
<ul>
<li>Names are '-' delimited (this goes for a C, E or M)
<pre><code class="language-css pseudo-code">.component-name {}</code></pre>
</li>
<li>Element classes have the component's name, then their name with a double underscore separator
<pre><code class="language-css pseudo-code">.component-name__element-name {}</code></pre>
</li>
<li>Modifiers are added to the end of a component or an element and are separated by a dash.
<pre><code class="language-css pseudo-code">
.component-name--modifier-name {}
.component-name__element-name--modifier-name {}</code></pre>
</li>
</ul>
</section>
</section>
<section>
<h2 id="menu-example">Menu Example</h2>
<pre><code class="language-scss pseudo-code">div.menu__wrapper {}
nav.menu {}
ul.menu__list {}
li.menu__list-item {}
a.menu__link {}
li.menu__list-item {}
a.menu__link.menu__link--active {}
li.menu__list-item {}
a.menu__link {}
ul.menu.menu--sub-menu {}
.menu__list {}</code></pre>
</section>
<section>
<h2 id="js-prefix">JS Prefix</h2>
<p>If a class is being used by or is coming from Javascript, it gets a "js-" prefix.</p>
<pre><code class="language-css pseudo-code">
.js-open {}
.js-accordion {}
.js-best-thing-you-ever-saw {}</code></pre>
</section>
<section>
<h3 id="pro-tip-utility-classes">Pro-tip*: Utility classes</h3>
<pre><code class="language-css pseudo-code">
.u-button {}
.u-clearfix {}
.u-text-replace {}
.u-element-invisible {}</code></pre>
<p class="small" style="position: relative; text-align: left; width: 75%; margin: 2em auto 0"><span style="position: absolute; left: -1em;">*</span> This is something we do at Lullabot on our BEM projects, and not something core is doing.</p>
<aside class="notes">
When you're using BEM, sometimes you end up having great use cases for a few utility classes, instead of repeating styles.
Prefix them with a "u-" so they're easy to spot.
</aside>
</section>
<section class="center">
<h1 id="very-lean-core-markup-and-styles">Very Lean Core Markup and Styles</h1>
</section>
<section>
<p>This is D8 with no theme CSS</p>
<img src="assets/d8/unthemed-d8.png" alt="A very bare looking web site" />
</section>
<section>
<section>
<h2 id="two-base-themes">Core's Base Themes</h2>
<div style="display: flex; text-align: left;">
<div style="padding: 0 1em 0 0; width: 50%">
<h3 id="classy-theme" style="font-weight: 200">Classy</h3>
<ul>
<li>Base theme for Seven and Bartik.</li>
<li>Has default theming D7 had in core.</li>
</ul>
</div>
<div style="padding: 0 0 0 1em; width: 50%">
<h3 id="stable-theme" style="font-weight: 200">Stable</h3>
<ul>
<li>Has bare minimum markup/styles needed for things to function.</li>
</ul>
</div>
</div>
<p>Both have well organized files, and all of the templates from core.</p>
</section>
<section class="center">
<div class="column-wrapper" style="justify-content: center; align-items: flex-end; font-weight: 600; margin-top: -4em;">
<div style="text-align: right; padding: 0 0 1em;">Classy</div>
<div style="width: 6em;">
<div style="color: #aaa; font-size: 3em; line-height: 1.2; font-weight: 800;">?</div>
<div style="color: #fff; border-radius: 50%; background: #128083; width: 4em; height: 4em; box-sizing: border-box; padding: 1em 0 0; margin: 0 auto;">⊙﹏⊙</div>
</div>
<div style="text-align: left; padding: 0 0 1em;">Stable</div>
</div>
<p style="padding: 2em 15% 0;">Starting your theming project, which is right for you?</p>
</section>
<section>
<div class="column-wrapper" style="justify-content: center; align-items: flex-end; font-weight: 600;">
<div style="text-align: right; padding: 0 0 1em;">Classy</div>
<div style="width: 6em;">
<div style="color: #aaa; font-size: 3em; line-height: 1.2; font-weight: 800; transform: translateX(-.3em);">!</div>
<div style="position: relative; color: #fff; border-radius: 50%; background: #128083; width: 4em; height: 4em; box-sizing: border-box; padding: 1em 0 0; margin: 0 auto;">
<span style="font-size: .6em; display: inline-block; transform: translateX(-1em)"><sup style="display: inline-block; transform: translate(0.3em, 0);">´</sup>◕ ᴗ ◕<sup style="display: inline-block; transform: translate(-0.3em, 0);">`</sup></span>
</div>
</div>
<div style="text-align: left; padding: 0 0 1em;">Stable</div>
</div>
<div style="padding: 2em 0 0;">
<p><strong>Liked D7's default markup and styles?</strong></p>
<em stlye="display: block">Classy is the base theme for you.</em>
</div>
</section>
<section>
<div class="column-wrapper" style="justify-content: center; align-items: flex-end; font-weight: 600;">
<div style="text-align: right; padding: 0 0 1em;">Classy</div>
<div style="width: 6em;">
<div style="color: #aaa; font-size: 3em; line-height: 1.2; font-weight: 800; transform: translateX(.3em);">!</div>
<div style="position: relative; color: #fff; border-radius: 50%; background: #128083; width: 4em; height: 4em; box-sizing: border-box; padding: 1em 0 0; margin: 0 auto;">
<span style="font-family: arial; font-size: .6em; display: inline-block; transform: translateX(1em)"><sup style="display: inline-block; transform: translate(0.3em, 0);">´</sup>◕ ᴗ ◕<sup style="display: inline-block; transform: translate(-0.3em, 0);">`</sup></span>
</div>
</div>
<div style="text-align: left; padding: 0 0 1em;">Stable</div>
</div>
<div class="column-wrapper">
<div style="padding: 2em 0 0;">
<p><strong>Frustrated by D7 defaults and want more control?</strong></p>
<em stlye="display: block">Use Stable</em>
<p>OR</p>
</div>
</div>
</section>
<section>
<div class="column-wrapper" style="justify-content: center; align-items: flex-end; font-weight: 600;">
<div style="text-align: right; padding: 0 0 1em;"><s>Classy</s></div>
<div style="width: 6em;">
<div style="color: #aaa; font-size: 3em; line-height: 1.2; font-weight: 800; transform: translateX(.3em);">!</div>
<div style="position: relative; color: #fff; border-radius: 50%; background: #128083; width: 4em; height: 4em; box-sizing: border-box; padding: 1em 0 0; margin: 0 auto;">
<span style="font-family: arial; font-size: .6em; display: inline-block; transform: translateX(0)"><sup style="display: inline-block; transform: translate(0.3em, 0);">´</sup>◕ <span style="font-size: 1em; position: relative; bottom: -0.5em; font-weight: 200;">³</span> ◕<sup style="display: inline-block; transform: translate(-0.3em, 0);">`</sup></span>
</div>
</div>
<div style="text-align: left; padding: 0 0 1em;"><s>Stable</s></div>
</div>
<div class="column-wrapper">
<div style="padding: 2em 0 0;">
<p><strong>Want the latest and greatest from core markup? Don't mind keeping up with markup updates?</strong></p>
<em stlye="display: block">You can have no base theme...</em>
</div>
</div>
</section>
<section>
<h3>Ride the roller coaster!</h3>
<p>In your <code>*.info.yml</code> add:</p>
<pre><code class="language-twig">base theme: false</code></pre>
<p>Core markup and classes <em>could</em> change and <em>could</em> effect your site.</p>
</section>
</section>
<section class="center">
<h1 id="twig-basics">Twig Basics</h1>
</section>
<section>
<pre><code class="language-twig" style="max-height: 9999em">
{# block.html.twig #}
<div{{ attributes }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
{% block content %}
{{ content }}
{% endblock %}
</div>
</code></pre>
<aside class="notes">If you've used Mustache/Handlebars, Angular, Templated in Blogger or Tumblr, this is very similar</aside>
</section>
<section>
<h2 id="basic-twig-syntax">Basic Twig Syntax</h2>
<p style="font-size: .9em; font-weight: 600; margin-bottom: .3em;">Print something</p>
<pre><code class="language-twig">Hi {{ name }}</code></pre>
<p style="font-size: .9em; font-weight: 600; margin-bottom: .3em;">Run code</p>
<pre><code class="language-twig">{% set class = 'my-cool-class' %}</code></pre>
<p style="font-size: .9em; font-weight: 600; margin-bottom: .3em;">Comment</p>
<pre><code class="language-twig">{# My awesome comment #}</code></pre>
</section>
<section>
<section class="center">
<h2 id="drilling-for-data">Drilling for Data in Templates</h2>
<h3 style="font-weight: 200">D7 vs. D8</h3>
</section>
<section>
<h3>Simple, Static Data</h3>
<h4 style="font-size: 1.2em">Drupal 7</h4>
<pre><code class="language-php">$title
$content['field_body']
$myvar['has']->alot['of']['nesting']['und'][0]->safe_value</code></pre>
<h4 style="font-size: 1.2em; margin-bottom: 0;">Drupal 8</h4>
<p style="margin: 0;">Dot notation</p>
<pre><code class="language-twig">{{ title }}
{{ content.field_body }}
{{ myvar.has.alot.of.nesting.safe_value }}</code></pre>
</section>
<section>
<h3 id="or-sometimes-you-need-array-notation">Tricksy Datas</h3>
<h4>Drupal 7</h4>
<pre><code class="language-php">$my_array[$index]
$element['#id']</code></pre>
<h4>Drupal 8</h4>
<pre><code class="language-twig">{# Since I want to use a variable called index #}
{{ my_array[index] }}
{# Since this index starts with a hash #}
{{ element['#id'] }}</code></pre>
</section>
</section>
<section>
<section>
<h3 id="the-blessing-and-curse-of-twig-s-dot-notation">Behind the scenes:</h3>
<pre style="font-size: .5em;"><code class="language-php" style="max-height: 9999em;">
/**
* If you have {{ sandwich.cheese }} in your twig, it checks:
*/
// 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');</code></pre>
<p class="small"><a href="http://twig.sensiolabs.org/doc/templates.html#variables">twig.sensiolabs.org/doc/templates.html#variables</a></p>
</section>
<section>
<h4>In other words...</h4>
<pre><code class="language-twig">{{ what.does.this.do }}</code></pre>
<div style="text-align:left">
<p><strong>It could be getting data, or performing functionality.</strong></p>
<p>This is helpful because it's more legible and less picky about syntax.</p>
<p>But it can be confusing if you’re not familiar with the code, and don't know which it's doing.</p>
</div>
</section>
</section>
<section class="center">
<h2 id="filters">Twig Filters</h2>
<p>Filters modify and then return variables, <br>and are denoted by a pipe | symbol.</p>
</section>
<section>
<section>
<h3 id="string-filters">Filter strings!</h3>
<pre><code class="language-twig">{# Send translatable string through t function #}
{{ 'Translatable String'|t }}
{# Make a string fit to be a HTML Class #}
{{ node.bundle|clean_class }}
{# Get the string length #}
{% set title_length = title|length %}</code></pre>
<p class="small">There are plenty more:
<br><a href="http://twig.sensiolabs.org/doc/filters/index.html">twig.sensiolabs.org/doc/filters/index.html</a>
<br><a href="https://www.drupal.org/node/2357633">drupal.org/node/2357633</a></p>
</section>
<section>
<h4 id="apply-a-string-filter-to-a-block-of-text">Apply a string filter to a block of text</h4>
<pre><code class="language-twig">
{% filter trim %}
Trim will eliminate this weird white space
{% endfilter %}</code></pre>
</section>
</section>
<section>
<h3 id="array-filters">Filter arrays!</h3>
<pre><code class="language-twig" style="max-height: 9999em;">
{# Without will omit part of the array,
this is being used instead of hide()/show() #}
{{ node|without('comments') }}
{# Get the keys of an array (as an array) #}
{% set my_array_keys = my_array|keys %}
{# Reverse the values #}
{% set countdown = [1, 2, 3, 4, 5]|reverse %}</code></pre>
<p class="small">There are plenty more: <a href="http://twig.sensiolabs.org/doc/filters/index.html">twig.sensiolabs.org/doc/filters/index.html</a></p>
</section>
<section>
<h2 id="if-else">If/Else</h2>
<pre><code class="language-twig">
{% if not page %}
{# Stuff #}
{% endif %}</code></pre>
<pre><code class="language-twig">
{% if not page %}
{# Stuff #}
{% else if page and awesome %}
{# Awesome Stuff #}
{% else %}
{# Other Stuff #}
{% endif %}</code></pre>
<p class="small"><a href="http://twig.sensiolabs.org/doc/tags/if.html">twig.sensiolabs.org/doc/tags/if.html</a></p>
</section>
<section>
<h2 id="for-loops">For Loops</h2>
<pre><code class="language-twig">{# A for loop that counts to 10 #}
{% for i in 0..10 %}
This is number {{ i }}!
{% endfor %}</code></pre>
<pre><code class="language-twig">{# A for loop that iterates through an array #}
{% for user in users %}
User #{{ loop.index }} is {{ user.username }}
{% endfor %}</code></pre>
<p class="small"><a href="http://twig.sensiolabs.org/doc/tags/for.html">twig.sensiolabs.org/doc/tags/for.html</a></p>
</section>
<section class="center">
<h1 id="yaml-and-beefed-up-config-functionality">YML and Beefed up Config Functionality</h1>
</section>
<section>
<section>
<h2 id="info-yaml">Info.yml</h2>
<pre><code class="language-yaml"># fluffiness.info.yml
name: Fluffiness
type: theme
description: A cuddly theme.
package: Custom
core: 8.x
libraries:
- fluffiness/global-styling
regions:
header: Header
content: Content
sidebar_first: Sidebar first
footer: Footer</code></pre>
<p class="small"><a href="https://www.drupal.org/node/2349827">drupal.org/node/2349827</a></p>
</section>
<section>
<h3 id="creating-a-sub-theme">Creating a sub theme</h3>
<pre><code class="language-yaml"># fluffiness.info.yml
name: Fluffiness
type: theme
description: A cuddly theme.
package: Custom
core: 8.x
base theme: classy</code></pre>
<p class="small"><a href="https://www.drupal.org/node/2165673">drupal.org/node/2165673</a></p>
</section>
</section>
<section>
<section>
<h2 id="libraries-yml">Libraries.yml</h2>
<pre><code class="language-yaml"># fluffiness.libraries.yml
global:
version: 1.x
css:
theme:
css/layout.css: {}
css/style.css: {}
css/colors.css: {}
css/print.css: { media: print }</code></pre>
<p class="small"><a href="https://www.drupal.org/theme-guide/8/assets">drupal.org/theme-guide/8/assets</a></p>
</section>
<section>
<h3 id="define-libraries-that-can-consist-of-js-and-css">Define Libraries that can consist of JS and CSS</h3>
<pre><code class="language-yaml"># Further down in fluffiness.libraries.yml
cuddly-slider:
version: 1.x
css:
theme:
css/cuddly-slider.css: {}
js:
js/cuddly-slider.js: {}</code></pre>
<p class="small"><a href="https://www.drupal.org/theme-guide/8/assets">drupal.org/theme-guide/8/assets</a></p>
</section>
<section>
<h3 id="declare-dependencies-on-other-libraries">Declare dependencies on other libraries</h3>
<pre><code class="language-yaml"># We forgot our jquery dependency!
cuddly-slider:
version: 1.x
css:
theme:
css/cuddly-slider.css: {}
js:
js/cuddly-slider.js: {}
dependencies:
- core/jquery</code></pre>
<p class="small"><a href="https://www.drupal.org/theme-guide/8/assets">drupal.org/theme-guide/8/assets</a></p>
</section>
</section>
<section>
<section class="center">
<h3 id="can-use-the-attached-method-to-add-libraries-using-php-in-theme-file-for-example-">Adding Libraries to specific pages</h3>
</section>
<section>
<h4>Using Twig</h4>
<p>For most use cases, you can tie a library to markup using <code>attach_library()</code></p>
<pre><code class="language-twig">{{ attach_library('fluffiness/cuddly-slider') }}
<div>Some fluffy markup {{ message }}</div></code></pre>
<p class="small"><a href="https://www.drupal.org/node/2216195">drupal.org/node/2216195</a></p>
</section>
<section>
<h4>Using PHP</h4>
<p>In your <code>.theme</code> file you can use PHP to add the library using whatever logic you'd like.</p>
<pre><code class="language-php" style="font-size: .8em"><?php
function fluffiness_preprocess_maintenance_page(&$variables) {
$variables['#attached']['library'][] = 'fluffiness/cuddly-slider';
}
function fluffiness_preprocess_page(&$variables) {
if ($variables['fluffiness'] >= 5000) {
$variables['#attached']['library'][] = 'fluffiness/cuddly-slider';
}
}</code></pre>
<p class="small"><a href="https://www.drupal.org/node/2216195">drupal.org/node/2216195</a></p>
</section>
</section>
<section>
<h2 id="breakpoints-yml">Breakpoints.YML</h2>
<pre><code class="language-yaml" style="font-size: .8em;"># fluffiness.breakpoints.yml
fluffiness.mobile:
label: mobile
mediaQuery: ''
weight: 2
multipliers:
- 1x
- 2x
fluffiness.narrow:
label: narrow
mediaQuery: 'all and (min-width: 560px) and (max-width: 850px)'
weight: 1
multipliers:
- 1x
- 2x
fluffiness.wide:
label: wide
mediaQuery: 'all and (min-width: 851px)'
weight: 0
multipliers:
- 1x</code></pre>
<p class="small"><a href="https://www.drupal.org/documentation/modules/breakpoint">drupal.org/documentation/modules/breakpoint</a></p>
</section>
<section class="center">
<h1 id="setting-up-your-local-for-theme-dev">Developing on your local</h1>
</section>
<section>
<h2 id="dumping-vars">Dumping vars</h2>
<pre><code class="language-twig">{# Will dump all vars available to the template #}
{{ dump() }}</code></pre>
<pre><code class="language-twig">
{# Or dump a specific variable #}
{{ dump(specific.var) }}</code></pre>
</section>
<section>
<h2 id="devel-amp-kint">Devel & Kint</h2>
<div style="text-align: left">
<p>At this point, don't use <strong>Devel</strong> to dump code unless you enable the <strong>Devel Kint</strong> sub module.</p>
<p>Kint will replace Krumo, and is usable inside of twig.</p>
</div>
<pre><code class="language-twig">{# Will dump all vars available to the template #}
{{ kint() }}</code></pre>
<pre><code class="language-twig">
{# Or dump a specific variable #}
{{ kint(specific.var) }}</code></pre>
</section>
<section>
<section>
<h2 id="services-yml-updates">Setup Twig Developer Settings</h2>
<ol style="font-size: 0.9em; text-align: left">
<li>
Find <code>twig.config</code> and change these values <small style="display: block">(should be in development.services.yml)</small>
<pre><code class="language-yaml"># Will be buried in the file, search for 'twig.config'
twig.config:
debug: true</code></pre>
</li>
<li>Add a <code>settings.local.php</code> file with:
<pre><code class="language-php"><?php
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';</code></pre>
</li>
</ol>
<p class="small"><a href="https://www.drupal.org/node/1903374">drupal.org/node/1903374</a></p>
</section>
</section>
<section class="slide39">
<h2 id="template-debug-in-d8">Template Debug in D8</h2>
<p>Once you've turned on twig debug, you'll get this:</p>
<pre><code class="language-markup" style="font-size: .8em;"><!-- THEME DEBUG -->
<!-- CALL: theme('block') -->
<!-- FILE NAME SUGGESTIONS:
* block--system.html.twig
* block--system-menu-block.html.twig
* block--system-menu-block--tools.html.twig
* block--bartik-tools.html.twig
x block.html.twig
-->
<!-- BEGIN OUTPUT from 'core/modules/block/templates/block.html.twig' -->
<div class="block block-system contextual-region block-menu" id="block-bartik-tools" role="navigation">
<!-- HTML stuff was here -->
</div>
<!-- END OUTPUT from 'core/modules/block/templates/block.html.twig' -->
</code></pre>
</section>
<section>
<h3 id="pro-tip-template-debug-was-added-to-d7-33-">Pro Tip: Template Debug was added to D7.33+</h3>
<p>Add this to your settings.php of choice:</p>
<pre><code class="language-php">$conf['theme_debug'] = TRUE;</code></pre>
</section>
<section class="center">
<h1 id="getting-into-the-weeds">Getting into the weeds</h1>
</section>
<section>
<section class="center">
<h2 id="overriding-libraries">Overriding Libraries</h3>
<p>Using your theme's *.info.yml</p>
</section>
<section>
<h3>Replace a library or asset</h3>
<pre><code class="language-yaml"># fluffiness.info.yml cont'd
libraries-override:
# Replace an entire library.
core/drupal.collapse: mytheme/collapse
# Replace an asset with another.
subtheme/library:
css:
theme:
css/layout.css: css/my-layout.css</code></pre>
<p class="small"><a href="https://www.drupal.org/node/2497313">drupal.org/node/2497313</a></p>
</section>
<section>
<h3>Removing an asset or entire library</h3>
<pre><code class="language-yaml"># OR in fluffiness.info.yml
libraries-override:
# Remove an asset.
drupal/dialog:
css:
theme:
dialog.theme.css: false
# Remove an entire library.
core/modernizr: false</code></pre>
<p class="small"><a href="https://www.drupal.org/node/2497313">drupal.org/node/2497313</a></p>
</section>
<section>
<h3>Extend a library</h3>
<pre><code class="language-yaml"># fluffiness.info.yml cont'd
# Extend drupal.user: add assets from classy's user libraries.
libraries-extend:
core/drupal.user:
- classy/user1
- classy/user2</code></pre>
<p class="small"><a href="https://www.drupal.org/node/2497313">drupal.org/node/2497313</a></p>
</section>
</section>
<section>
<section>
<h2 id="no-theme-functions-">Render Types</h2>
<div style="text-align: left">
<p>The render arrays of tomorrow!</p>
<p>Look for <code>#type</code> in render arrays</p>
</div>
<pre><code class="language-php"><?php
$variables['link'] = array(
'#type' => 'link',
'#title' => 'Visit Lullabot',
'#url' => 'https://lullabot.com',
'#options' => array(
'class' => array(
'some-class',
),
),
);</code></pre>
</section>
<section>
<h3>Modifying Render Elements</h3>
<p>Unfortunately, the easiest way I've found is to modify it in the preprocessor.</p>
<pre><code style="font-size: 0.8em;" class="language-php"><?php
/**
* Implements template_preprocess_menu_local_task().
*/
function frontendrapport_preprocess_menu_local_task(&$variables) {
$variables['link']['#options']['attributes']['class'][] = 'admin-tabs__link';
}</code></pre>
</section>
</section>
<section>
<section>
<h2 id="speaking-of-theme_suggestions-">ALL the <code>theme_suggestions</code></h2>
<div style="text-align: left">
<p>They're all done in one place, no longer buried in preprocessor code!</p>
<pre style="width: 100%;"><code class="language-php" style="font-size: .8em;">hook_theme_suggestions_alter(array &$suggestions, array $variables, $hook)</code></pre>
<p class="small" style="text-align: center"><a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_theme_suggestions_alter/8">api.drupal.org docs for theme_suggestions</a></p>
</div>
</section>
<section>
<h3>I see less <code>hook_form_alter()</code> in your future...</h3>
<p style="text-align: left;">Instead of using <code style="display: inline-block; padding: 0 .3em; color: #225378">hook_form_alter()</code> to add a bit of presentation to a form you can suggest a specific template for the form or any of it's fields!</p>
</section>
</section>
<section>
<h2 id="attribues-object-your-new-friend-">Attributes Object, your new friend!</h2>
<pre><code class="language-twig"><div{{ attributes }}></code></pre>
<p style="margin-top: 2em; text-align: left">No extra space needed</p>
<pre><code class="language-twig">{# ↓ Don't need this space #}
<div {{ attributes }}></code></pre>
<p class="small"><a href="https://www.drupal.org/node/2513632">drupal.org/node/2513632</a></p>
</section>
<section>
<pre><code class="language-twig" style="max-height: 9999em; font-size: .9em;">{# Add or Remove Classes #}
<div{{ attributes.addClass('my-class') }}>
<div{{ attributes.removeClass('their-class') }}>
{# Set any attribute #}
<div{{ attributes.setAttribute('id', 'myID') }}>
<div{{ attributes.setAttribute('data-bundle', node.bundle) }}>
{# Remove any attribute #}
<div{{ attributes.removeAttribute('id') }}>
{# hasClass boolean! #}
{% if attribute.hasClass('myClass') %}
{# do stuff #}
{% endif %}</code></pre>
<p class="small"><a href="https://www.drupal.org/node/2513632">drupal.org/node/2513632</a></p>
</section>
<section>
<h3 id="attributes-methods-can-be-chained">Attributes methods can be chained</h3>
<pre><code class="language-twig" style="font-size: .9em;"><div{{ attributes.addClass('hello').removeClass('goodbye') }}></code></pre>
</section>
<section>
<h2 id="best-practices-encourage-a-bit-more-logic-in-the-template-files">D8 encourages more classes to be set in Twig</h2>
<pre><code class="language-twig">{%
set classes = [
'node--' ~ node.bundle|clean_class,
'node--my-custom-modifier',
]
%}
<article{{ attributes.addClass(classes) }}></code></pre>
<p style="text-align: left">In D7 this would have been done in the preprocessor.</p>
</section>
<section>
<section>
<h2 id="there-are-twig-extends-11">Twig Extends</h2>
<pre><code class="language-twig">{# cool.html.twig #}
{% block foo %}
Default content
{% endblock %}</code></pre>
<p>Meanwhile...</p>
<pre><code class="language-twig">{# cool-er.html.twig #}
{% extends "cool.html.twig" %}
{% block foo %}
Alternate Content
{% endblock %}</code></pre>
<p class="small"><a href="http://twig.sensiolabs.org/doc/tags/extends.html">twig.sensiolabs.org/doc/tags/extends.html</a></p>
</section>
<section>
<h3>And you can even...</h3>
<pre><code class="language-twig">{# cool-er.html.twig #}
{% extends "cool.html.twig" %}
{% block foo %}
{{ parent() }}
Alternate Content
{% endblock %}</code></pre>
</section>
<section>
<h3>Editorial time...</h3>
<p>Extends make a tonne of sense for custom Symfony applications...</p>
<p>But in Drupal land they might make code DRYer at the expense of being intuitive.</p>
</section>
</section>
<section class="center">
<h1 id="questions">Questions?</h1>
</section>
<section style="text-align: left">
<h1 id="sources">Sources</h1>
<div style="font-size: .8em">
<p><strong><a href="https://events.drupal.org/losangeles2015/sessions/drupal-8-theme-system-hooktheme-twig-template">Drupal 8 Theme System: hook_theme() to Twig template</a></strong> - Cottser and Joel Pittet at DrupalCon LA
<a style="font-size: .5em; display: block;" href="https://events.drupal.org/losangeles2015/sessions/drupal-8-theme-system-hooktheme-twig-template">events.drupal.org/losangeles2015/sessions/drupal-8-theme-system-hooktheme-twig-template</a></p>
<p><strong><a href="https://events.drupal.org/losangeles2015/sessions/drupal-8-theming">Drupal 8 Theming with <3</a></strong> - Morten DK at DrupalCon LA
<a style="font-size: .5em; display: block;" href="https://events.drupal.org/losangeles2015/sessions/drupal-8-theming">events.drupal.org/losangeles2015/sessions/drupal-8-theming</a></p>
<p><strong><a href="https://www.drupal.org/coding-standards/css/architecture">Theming in Drupal 8</a></strong> - Drupal.org
<a style="font-size: .5em; display: block;" href="https://www.drupal.org/coding-standards/css/architecture">drupal.org/coding-standards/css/architecture</a></p>
<p><strong><a href="http://twig.sensiolabs.org/documentation">Twig Official Documentation</a></strong> - twig.sensiolabs.org
<a style="font-size: .5em; display: block;" href="http://twig.sensiolabs.org/documentation">twig.sensiolabs.org/documentation</a></p>
<p><strong><a href="https://www.lullabot.com/articles/drupal-8-theming-fundamentals-part-1">Drupal 8 Theming Fundamentals</a></strong> - John Hannah<br>
<a style="font-size: .5em; display: block;" href="https://www.lullabot.com/articles/drupal-8-theming-fundamentals-part-1">lullabot.com/articles/drupal-8-theming-fundamentals-part-1</a></p>
</div>
</section>
</div>
</div>
<script src="plugin/prism/prism.js"></script>
<script src="dist/reveal.js"></script>
<script src="plugin/zoom/zoom.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/search/search.js"></script>
<script>
// Also available as an ES module, see:
// https://revealjs.com/initialization/
Reveal.initialize({
controls: true,
progress: true,
center: true,
hash: true,
// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealZoom, RevealNotes, RevealSearch ]
});
</script>
</body>
</html>