Integrating the 50/50 component
Exercise: Creating twig templates for blog posts
In your Drupal site, navigate to "Recent Blogs" (i.e. /recent-blogs)
Right-click on any of the Blog posts articles and select Inspect or Inspect Element
Scroll up in the inspector's code until you find the
<article>element that wraps the entire article you clicked on. There may be multiple<article>tags within each article, but ensure you are looking at the main article wrapper. See screenshot below (click on it to zoom in):

THEME HOOK: Tells you what entity you are currently looking at. In this example we are looking at the node, which is what we want since we are trying to configure the Blog nodes with the right component.
By examining the template suggestion names, we can easily identify that we are dealing with a node. All the template suggestions for this entity type start with the word "node--*". This naming convention provides us with the flexibility to be as specific or general as required, allowing us to target the desired template for customization.
Current we are using the default node template provided by the Stable9 base theme. We want to create a more specific presenter template that will integrate node teasers with out 50/50 teaser component.
Creating a template for the node teaser view mode
The focus at this point is to create template suggestions for all nodes that will be displayed in the Teaser view mode. We could target article nodes specifically but instead we are going to apply this integration to all nodes. If we change our minds later we can always rename the template to a more specific article teaser suggestion.
Create a new template named
node--teaser.html.twigin your teaser templates folder at/themes/custom/training_theme/src/stories/components/teaser/templates/.Add a word like TEST so that you will be able to verify Drupal picked up the new template suggestion next time you clear caches.
Clear your Drupal's cache.
Reload the page and verify that you can see your new custom template.
Integrating the 50/50 component
OK, now that our custom twig template is ready, it's time to plug it to our 50/50 component so our blog posts look styled.
Open node--teaser.html.twig in your editor and replace your code with the following code.
Some things to notice:
Similar to our block teaser we have added some wrapper markup and the title prefix/suffix variables for contextual links
Many of the field mappings look the same as our block entity because our node uses fields of the same name as our "Teaser" block.
Rendering our updated teasers
Now that the teaser integration is complete, let's take a look at how the blog nodes look in Drupal.
After saving all your changes to node--teaser.html.twig, clear Drupal's cache
Reload the page.
After loading the page you should see blog teasers rendered using our 50/50 component template.

Now our page is complete and should also render contextual links when you hover over a node teaser.
Last updated