Drupal 8
Drupal 7 has a really handy list of view templates... which is missing in D8/D9.... it doesn't even show up in the template suggestions that show if theme debug is switched on... which is not so handy! So let me see if I can explain how this works. I'm using 'Stable' as a base theme and the initial…
In D7 the copyright line in a tpl.php file might look like this:
<p>© Copyright <?php echo date('Y'); ?> Company Name</p>
In D8/9 the TWIG template needs to be like this:
<p>© Copyright {{ currentYear|raw }} Company Name</p>
D7 to D8/9 Differences
D7: print render($page['help']);
D8/9: {{ page.help }}
D7:
<?php if($page['sidebar_first']){ ?>
<div class="sidebar-first">
<?php print render($page['sidebar_first']); ?>
</div>
<?php } ?>
D8/9:
{% if page.…
{% if content.field_inner_hero %}
<div id="innerhero">
{{ content.field_inner_hero }}
</div>
{% endif %}
Better
{% if content.field_inner_hero[0] %}
<div id="innerhero">
{{ content.field_inner_hero }}
</div>
{% endif %}
{{ title_prefix }}
{% if title %}
<h1{{ title_attributes.addClass('title').setAttribute('id', 'page-title') }}>{{ title }}</h1>
{% endif %}
{{ title_suffix }}
Another way
<div id="nodebody{{ node.id }}" {{ content_attributes.addClass('nodearticle') }}>
This is such a vital part of the build process for D8/9 that it's a shame it's not something you just tick in the CMS. Then again, I believe the idea is to have the additional settings/files on your local machine and not on your production server. That way the production server is always fully…
In Drupal 8/9 you create a MYTHEME.info.yml file to specify the theme name, and base themes (if this is a child theme), regions, etc. One of the items is a reference to your 'libraries'.
name: MYTHEME
type: theme
description: Custom Drupal 9 theme
base theme: stable
core_version_requirement: ^8…