I'm been theming in Drupal 8 for almost 2 months everyday 5+ hours @ day.
There is some good stuff that I have learn while building d8_materialize I started this when D8 was in beta.
And there is some good stuff that I learn building ablog >
Demo ablog
Demo materialize
Demo Drupal Camp GDL
Did you notice the x instead of the *
Usage:
{{ kint(content) }}
Install:
https://www.drupal.org/project/devel
For me the most useful, it shows you all the arrays, objects and variables that are passed to your template.
{{ content.field_user_reference }}
This prints the render array of the user reference.
this arrangement makes more sense to me. ---->
@core Classy
@My theme
views-view--machine-name.html.twig
1.- Declare the library
2.- Use the library
MYTHEME.libraries.yml
views_exposed_filters:
version: 1
js:
js/custom/view-exposed-filters.js: {}
{{ attach_library('ixia/views_exposed_filters') }}
<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
{% if title %}
{{ title }}
{% endif %}
{{ title_suffix }}
</div>
Example:
twig access:
{{ directory }}
Example:
twig access:
{{ elements.content.field_hero_background_image }}
Example:
twig access:
{{ content.field_hero_background_image['#title'] }}
arrays with # need to be accessed with the brackets
Example:
twig access:
{{ content.field_hero_background_image[1]['#title'] }}
[0]['#title']
Example:
twig access:
{{ content['#block_content'] }} << object
Example:
twig access:
{{ content['#block_content'].get('field_hero_background_image').getValue() }}
^^^^ this will return an array. ^^^^^
{{ content['#block_content'].get('field_hero_background_image').getValue()[0]['alt'] }}
^^^^ this will return: "Hombre de fuego hero banner". ^^^^^
{{ content['#block_content'].get('field_hero_background_image').getValue()[1]['alt'] }}
^^^^ this will return: "Hero SF Banner". ^^^^^
{% set number_of_files = content.field_files['#items'].getIterator() | length %}
{% set author_name_string = node.get('field_author').get(0).entity.getDisplayName() %}
{% set author_name_string = node.get('field_author').get(0).entity.getDisplayName() %}
{% trans %} is for translate
keep the date filter out of the trans, if you keep it inside is going to fail
Do site building first, get your values in the format that you want from the view modes.
It is hard to do it programmatically and with preprocess.
Use https://www.drupal.org/project/views_field_formatter
Use views as display mode, create a view and pass a contextual param.
theme settings reminds me Drupal 7, because is the same thing.
create a file named theme-settings.php inside your theme.
/**
* Implements hook_form_system_theme_settings_alter().
*/
{{ title_suffix }}