Creating your theme
Themes have relocated. Just like modules, themes now live in the root of your Drupal installation. You can find them under themes directory. By convention you can separate themes into contributed and custom by creating themes/contrib and themes/custom folders.
As usual, each theme lives in its own directory. I will name my theme ‘example’ and place it into themes/custom/example folder.
To let Drupal know about my theme I will need to create an info file with basic information. In Drupal 8 we do this with a .info.yml file since Drupal 8 is now using yaml language when configuring settings. In my case, I will create example.info.yml with the following content:
name: Example theme
description: 'An example D8 theme'
package: Custom
type: theme
version: 1.0
core: 8.x
This is all similar to Drupal 7 info file except it is written in yml.
With this file in place, we have created an independent stand alone custom theme. However, if you wanted to extend already existing theme you can add the following directive to the file:
base theme: classy
Classy is the name of a base theme in Drupal 8 that comes with sensible defaults.
More configuration
Now that we have our theme available to Drupal, let’s have a look at what other options can be declared in the info file.
By default, the theme’s screenshot (as seen in the user interface) would be read from screenshot.png file. If you have a file with a different extension or it is located somewhere else other than theme’s root directory you can use the following syntax to specify the screenshot’s location:
screenshot: screenshot.svg
Next we can add stylesheets and javascript libraries. This is one of the features that is completely different from Drupal 7.
Both javascript and css files are now considered ‘libraries’ and should be declared in a separate file: example.libraries.yml, which should live in the theme’s root folder – themes/custom/example/example.libraries.yml
Here is an example of the libraries.yml definition:
global-library:
version: VERSION
js:
js/scripts.js: {}
css:
base:
css/base/styles.css: {}
components:
css/components/components.css: {}
dependency:
- core/drupal
- core/jquery
other-library
version: VERSION
css:
base:
css/other-lib/styles.css: {}
There are 2 libraries defined in this file: global-library and other-library, each with its own css/js files and dependencies. To make one of these libraries globally available (in other words- to make this library load on every page) you will need to include it in example.info.yml in the following way:
libraries:
- example/global-library
To include any particular library on a specific page it should be included via one of the theme’s preprocess hooks or directly in a template file using twig’s function:
{{ attach_library('example/other-library') }}
The only template that doesn’t support this function is html.html.twig.
By the way, all ‘preprocess’ functions should be placed in the theme’s root directory in the example.theme file. This .theme file is a descendent of Drupal 7 template.php.
See the following example further fown in the article:
example_preprocess_page(&$variables)
There is one more useful directive that we could use in info.yml file and this is stylesheets-remove. If for example you don’t want the default system theme to include jquery.ui/themes/base/dialog.css, for example, simply add it to the stylesheets-remove directive. To find its full path use browser web tool like FireBug or Chrome’s built in inspector.
stylesheets-remove:
- core/assets/vendor/jquery.ui/themes/base/dialog.css
- '@bartik/css/style.css'
Visit website 2001
Visit website 2002
Visit website 2003
Visit website 2004
Visit website 2005
Visit website 2006
Visit website 2007
Visit website 2008
Visit website 2009
Visit website 2010
Visit website 2011
Visit website 2012
Visit website 2013
Visit website 2014
Visit website 2015
Visit website 2016
Visit website 2017
Visit website 2018
Visit website 2019
Visit website 2020
Visit website 2021
Visit website 2022
Visit website 2023
Visit website 2024
Visit website 2025
Visit website 2026
Visit website 2027
Visit website 2028
Visit website 2029
Visit website 2030
Visit website 2031
Visit website 2032
Visit website 2033
Visit website 2034
Visit website 2035
Visit website 2036
Visit website 2037
Visit website 2038
Visit website 2039
Visit website 2040
Visit website 2041
Visit website 2042
Visit website 2043
Visit website 2044
Visit website 2045
Visit website 2046
Visit website 2047
Visit website 2048
Visit website 2049
Visit website 2050
Visit website 2051
Visit website 2052
Visit website 2053
Visit website 2054
Visit website 2055
Visit website 2056
Visit website 2057
Visit website 2058
Visit website 2059
Visit website 2060
Visit website 2061
Visit website 2062
Visit website 2063
Visit website 2064
Visit website 2065
Visit website 2066
Visit website 2067
Visit website 2068
Visit website 2069
Visit website 2070
Visit website 2071
Visit website 2072
Visit website 2073
Visit website 2074
Visit website 2075
Visit website 2076
Visit website 2077
Visit website 2078
Visit website 2079
Visit website 2080
Visit website 2081
Visit website 2082
Visit website 2083
Visit website 2084
Visit website 2085
Visit website 2086
Visit website 2087
Visit website 2088
Visit website 2089
Visit website 2090
Visit website 2091
Visit website 2092
Visit website 2093
Visit website 2094
Visit website 2095
Visit website 2096
Visit website 2097
Visit website 2098
Visit website 2099
Visit website 2100
Visit website 2101
Visit website 2102
Visit website 2103
Visit website 2104
Visit website 2105
Visit website 2106
Visit website 2107
Visit website 2108
Visit website 2109
Visit website 2110
Visit website 2111
Visit website 2112
Visit website 2113
Visit website 2114
Visit website 2115
Visit website 2116
Visit website 2117
Visit website 2118
Visit website 2119
Visit website 2120
Visit website 2121
Visit website 2122
Visit website 2123
Visit website 2124
Visit website 2125
Visit website 2126
Visit website 2127
Visit website 2128
Visit website 2129
Visit website 2130
Visit website 2131
Visit website 2132
Visit website 2133
Visit website 2134
Visit website 2135
Visit website 2136
Visit website 2137
Visit website 2138
Visit website 2139
Visit website 2140
Visit website 2141
Visit website 2142
Visit website 2143
Visit website 2144
Visit website 2145
Visit website 2146
Visit website 2147
Visit website 2148
Visit website 2149
Visit website 2150
Visit website 2151
Visit website 2152
Visit website 2153
Visit website 2154
Visit website 2155
Visit website 2156
Visit website 2157
Visit website 2158
Visit website 2159
Visit website 2160
Visit website 2161
Visit website 2162
Visit website 2163
Visit website 2164
Visit website 2165
Visit website 2166
Visit website 2167
Visit website 2168
Visit website 2169
Visit website 2170
Visit website 2171
Visit website 2172
Visit website 2173
Visit website 2174
Visit website 2175
Visit website 2176
Visit website 2177
Visit website 2178
Visit website 2179
Visit website 2180
Visit website 2181
Visit website 2182
Visit website 2183
Visit website 2184
Visit website 2185
Visit website 2186
Visit website 2187
Visit website 2188
Visit website 2189
Visit website 2190
Visit website 2191
Visit website 2192
Visit website 2193
Visit website 2194
Visit website 2195
Visit website 2196
Visit website 2197
Visit website 2198
Visit website 2199
Visit website 2200
Visit website 2201
Visit website 2202
Visit website 2203
Visit website 2204
Visit website 2205
Visit website 2206
Visit website 2207
Visit website 2208
Visit website 2209
Visit website 2210
Visit website 2211
Visit website 2212
Visit website 2213
Visit website 2214
Visit website 2215
Visit website 2216
Visit website 2217
Visit website 2218
Visit website 2219
Visit website 2220
Visit website 2221
Visit website 2222
Visit website 2223
Visit website 2224
Visit website 2225
Visit website 2226
Visit website 2227
Visit website 2228
Visit website 2229
Visit website 2230
Visit website 2231
Visit website 2232
Visit website 2233
Visit website 2234
Visit website 2235
Visit website 2236
Visit website 2237
Visit website 2238
Visit website 2239
Visit website 2240
Visit website 2241
Visit website 2242
Visit website 2243
Visit website 2244
Visit website 2245
Visit website 2246
Visit website 2247
Visit website 2248
Visit website 2249
Visit website 2250
Visit website 2251
Visit website 2252
Visit website 2253
Visit website 2254
Visit website 2255
Visit website 2256
Visit website 2257
Visit website 2258
Visit website 2259
Visit website 2260
Visit website 2261
Visit website 2262
Visit website 2263
Visit website 2264
Visit website 2265
Visit website 2266
Visit website 2267
Visit website 2268
Visit website 2269
Visit website 2270
Visit website 2271
Visit website 2272
Visit website 2273
Visit website 2274
Visit website 2275
Visit website 2276
Visit website 2277
Visit website 2278
Visit website 2279
Visit website 2280
Visit website 2281
Visit website 2282
Visit website 2283
Visit website 2284
Visit website 2285
Visit website 2286
Visit website 2287
Visit website 2288
Visit website 2289
Visit website 2290
Visit website 2291
Visit website 2292
Visit website 2293
Visit website 2294
Visit website 2295
Visit website 2296
Visit website 2297
Visit website 2298
Visit website 2299
Visit website 2300
Visit website 2301
Visit website 2302
Visit website 2303
Visit website 2304
Visit website 2305
Visit website 2306
Visit website 2307
Visit website 2308
Visit website 2309
Visit website 2310
Visit website 2311
Visit website 2312
Visit website 2313
Visit website 2314
Visit website 2315
Visit website 2316
Visit website 2317
Visit website 2318
Visit website 2319
Visit website 2320
Visit website 2321
Visit website 2322
Visit website 2323
Visit website 2324
Visit website 2325
Visit website 2326
Visit website 2327
Visit website 2328
Visit website 2329
Visit website 2330
Visit website 2331
Visit website 2332
Visit website 2333
Visit website 2334
Visit website 2335
Visit website 2336
Visit website 2337
Visit website 2338
Visit website 2339
Visit website 2340
Visit website 2341
Visit website 2342
Visit website 2343
Visit website 2344
Visit website 2345
Visit website 2346
Visit website 2347
Visit website 2348
Visit website 2349
Visit website 2350
Visit website 2351
Visit website 2352
Visit website 2353
Visit website 2354
Visit website 2355
Visit website 2356
Visit website 2357
Visit website 2358
Visit website 2359
Visit website 2360
Visit website 2361
Visit website 2362
Visit website 2363
Visit website 2364
Visit website 2365
Visit website 2366
Visit website 2367
Visit website 2368
Visit website 2369
Visit website 2370
Visit website 2371
Visit website 2372
Visit website 2373
Visit website 2374
Visit website 2375
Visit website 2376
Visit website 2377
Visit website 2378
Visit website 2379
Visit website 2380
Visit website 2381
Visit website 2382
Visit website 2383
Visit website 2384
Visit website 2385
Visit website 2386
Visit website 2387
Visit website 2388
Visit website 2389
Visit website 2390
Visit website 2391
Visit website 2392
Visit website 2393
Visit website 2394
Visit website 2395
Visit website 2396
Visit website 2397
Visit website 2398
Visit website 2399
Visit website 2400
Visit website 2401
Visit website 2402
Visit website 2403
Visit website 2404
Visit website 2405
Visit website 2406
Visit website 2407
Visit website 2408
Visit website 2409
Visit website 2410
Visit website 2411
Visit website 2412
Visit website 2413
Visit website 2414
Visit website 2415
Visit website 2416
Visit website 2417
Visit website 2418
Visit website 2419
Visit website 2420
Visit website 2421
Visit website 2422
Visit website 2423
Visit website 2424
Visit website 2425
Visit website 2426
Visit website 2427
Visit website 2428
Visit website 2429
Visit website 2430
Visit website 2431
Visit website 2432
Visit website 2433
Visit website 2434
Visit website 2435
Visit website 2436
Visit website 2437
Visit website 2438
Visit website 2439
Visit website 2440
Visit website 2441
Visit website 2442
Visit website 2443
Visit website 2444
Visit website 2445
Visit website 2446
Visit website 2447
Visit website 2448
Visit website 2449
Visit website 2450
Visit website 2451
Visit website 2452
Visit website 2453
Visit website 2454
Visit website 2455
Visit website 2456
Visit website 2457
Visit website 2458
Visit website 2459
Visit website 2460
Visit website 2461
Visit website 2462
Visit website 2463
Visit website 2464
Visit website 2465
Visit website 2466
Visit website 2467
Visit website 2468
Visit website 2469
Visit website 2470
Visit website 2471
Visit website 2472
Visit website 2473
Visit website 2474
Visit website 2475
Visit website 2476
Visit website 2477
Visit website 2478
Visit website 2479
Visit website 2480
Visit website 2481
Visit website 2482
Visit website 2483
Visit website 2484
Visit website 2485
Visit website 2486
Visit website 2487
Visit website 2488
Visit website 2489
Visit website 2490
Visit website 2491
Visit website 2492
Visit website 2493
Visit website 2494
Visit website 2495
Visit website 2496
Visit website 2497
Visit website 2498
Visit website 2499
Visit website 2500