Drupal 8 Frontend Cheat Sheet
Drupal 8 Frontend Cheat Sheet
hook_library_info_alter(&$libraries, $module)
LIBRARIES (THEME.libraries.yml) hook_js_settings_alter(&$settings, $assets)
hook_js_alter(&$javascript, $assets)
global-styling:
hook_css_alter(&$css, $assets)
Drupal 8 Theming version: VERSION
css: hook_library_info_build()
theme:
INFO FILE (THEME.info.yml) css/style.css: {}
css/ie8.css: { IE: 'lte IE 8', !IE:
SCHEMA (THEME.schema.yml)
name: Example false } example.settings:
type: theme js: type: theme_settings
base theme: classy js/vendor/mondernizr.min/js label: 'Example settings'
description: 'An example theme.' { minified: true } example.breakpoints:
package: Custom dependencies: type: theme_breakpoints_default
core: 8.x - core/jquery label: 'Example breakpoints'
version: 8.x-1.0
screenshot: example_screenshot.png maintenance-page:
libraries:
- example/global-styling
version: VERSION TWIG
css: <a href="{{ path('node.type_add') }}">
stylesheets-override: theme: {{ ... }} Does output. {{ path('user.register') }}
- css/normalize.css css/theme/maintenance-page.css: {} {% ... %} Does control. {{ path('user.register', {}, {'fragment':
stylesheets-remove: 'bottom' }) }}
Library name (1st level, e.g. 'global-styling') must {# ... #} Does nothing (= comment).
- system.theme.css
match the library definition in THEME.info.yml. ~ Concatenates strings See: UrlGeneratorInterface::generateFromRoute()
regions:
header: Header {{ title }} {{ link(item.title, item.url) }}
primary_menu: 'Primary menu' example-styling:
version: 12.34.5 {{ content.links }} See: LinkGeneratorInterface::generate()
secondary_menu: 'Secondary menu' <h2{{ title_attributes }}>{{ label }}</h2>
help: Help header: true
{% if node.isPromoted() %} {% endif %}
highlighted: Highlighted css: Drupal Twig functions:
js: {% set classes = [ 'message', 'message--' ~
breadcrumb: Breadcrumb type ] %}
content: Content dependencies:
{% set args = { '@login': user_login_url }
footer: Footer version Library version. TWIG FILTERS {{ ...|example }}
%}
regions_hidden: header false, true. JS is placed in header. {% set tag = header ? 'th' : 'td' %} {{ data.degrees|abs }}
- sidebar_first: 'Sidebar first' dependencies Array of required libraries. See <div{{ attributes.addClass(classes) }}> {{ items.first.text|default(' first'|t) }}
- sidebar_second: 'Sidebar second' *.libraries.yml for library names. {{ data.width|e }}, {{ data.width|escape }}
stylesheets-remove: The filename of the css file to be css: {{ items|join(', ') }}
removed. Do not include a path. base: TWIG FUNCTIONS {{ example(...) }} {% if messages|length > 1 %}
stylesheets-override: The filename must match the layout: {{ item.id|replace({'/': '-'}) }}
component: <section{{ attributes.addClass(classes) }}>
overridden file. Path to the css file is {% if status is constant('MARK_NEW') %}
http://twig.sensiolabs.org/doc/filters/index.html
state:
relative to the theme path. striping ? cycle(['odd', 'even'],
theme:
regions_hidden: Always hidden regions (in the Blocks loop.index0)
CSS groups according to SMACCS categories. DRUPAL TWIG FILTERS
interface): page_top, page_bottom. parent()
<li{{item.attributes.removeClass('leaf')}}>
file.ext { type: external, weight: -1, \Drupal\Core\Template\TwigExtension
every_page: true, media: print, http://twig.sensiolabs.org/doc/functions/index.html \Drupal\Core\Template\TwigExtension::getFilters
BREAKPOINTS (THEME.breakpoints.yml)
preprocess: false, browsers: { IE: 'lte
example.mobile: IE 8', '!IE': false }, minified: true } 'field-type-' ~ field_type|clean_class
DRUPAL TWIG FUNCTIONS
label: mobile type file, external 'view-' ~ id|clean_class,
mediaQuery: '(min-width: 0em)' weight -100 (first) 0 100 (last) \Drupal\Core\Template\Attribute See: Html::getClass($class)
weight: 0 every_page false, true. Is loaded on every page.
multipliers:
\Drupal\Core\Template\TwigExtension::getFunctions
media all, print, etc. attributes.id ~ '-menu'|clean_id
- 1x 'show-'~ attributes.id|clean_id
example.wide: preprocess true, false. Asset file aggregation. <a href="{{ url('<front>') }}">
browsers Browser condition strings. {{ url('user.register') }} See: Html::getId
label: wide
mediaQuery: 'all and (min-width: 40em)' minified false, true url('user.register', {}, {'fragment':
weight: 1 'bottom' })
See: UrlGeneratorInterface::generateFromRoute()