To take it one step further, you can have a field.html.twig and field--field-long-text.html.twig. In that case, it makes no difference what directory they are in (as long as they are somewhere in the theme/templates directory). Drupal will use the field.html.twig for every field except fields with the machine name of field_long_text when it will use the template you created with the more specific name.
Then in Drupal, the paragraph--text.html.twig file uses include to bring in the entire content of the Pattern Lab paragraph-text.twig file and replaces the text variable with the Drupal output of the long text field in my text paragraph bundle content.field_long_text .
The Drupal template paragraph--text.html.twig both extends and embeds templates. It extends the Drupal paragraph.html.twig to add bring global classes and html structure into the text bundle template and it embeds the Pattern Lab text.twig template in place of the parent paragraph.html.twig content block while replacing the text variable with the Drupal content.field_long_text variable. Adding comments to the plwidgetopen and plwidgetclose blocks prevents them from printing the paragraph structure created in Pattern Lab.
I'm trying to use Drupal 8, with an own theme, due big structure differences for my requirements I have a page--front.twig.html and a page.twig.html, I would like to create template parts as used in phrozn oder in a normal Symfony2 project, for example a footer.html.twig and a header.html.twig. These templates are saved under a subdirectory /parts/
Below is an example of the potential output. The line item beginning with an "x" is the twig template that is used for this element. The rest are registered file naming suggestions that you can use as an override.
Lately I have been working with Drupal 8 trying to get my head around what it takes to create a production application in the latest version of Drupal. One of the very first snags I hit was theming. Working with the theme system in Drupal 8 is quite a bit different from Drupal 7 beings how Drupal 8 utilizes Twig as the theme engine instead of PHPTemplate. Drupal 8 was my first exposure to Twig so diving right into development came with a bit of a learning curve to get started. I was under the impression that I could start altering the theme templates right away and I could see the results when the page was reloaded. No dice! To remedy this I figured I could turn off site caching and I would be able to see my template changes immediately. Still, no dice! At this point I knew that there must be more going on under the hood so I figured I better go back and read the documentation on how Twig works within Drupal to get a better understanding of what is going on. It turns out that Twig templates are compiled into PHP code and the output is stored in memory for added performance boosts. Clearing the Drupal site cache will wipe out these compiled templates and you will be able to see your template changes, but for continuous theme development, this is not an optimal workflow. So, how can you disable Twig's template cache? In further reading of the documentation I found that the Twig's caching settings are available in the site's services.yml file located at /sites/default/services.yml. In altering these settings you will be able to see your template changes every time you reload the page without having to flush the Drupal site cache.
Drupal 7 would have multiple files with the same lines of code, including:
Drupal 8 uses lines like this: % extends "node.html.twig" %. Twig integration eliminates the need for copying and pasting base or parent theme template files into your custom templates. This means you can use proper inheritance inside your theme files and eliminate a lot of duplicate code.
This course will give you a deep understanding of advanced Drupal theming concepts. You'll learn how to use advanced functions in Twig, customize and extend a Drupal theme, analyze and resolve common theming issues, work with CSS and JavaScript for Drupal themes, and much more.
The extends statement is the foundation of template inheritance. It enables you to create a base template with common elements and then extend or override specific sections in child templates. This promotes consistency and reduces redundancy in your theming. Some examples are below.
Twig is a modern, fast and secure template framework that helps developers in developing new templates and manipulating existing templates effectively. There are lots of differences between the PHP templates and Twig.
Twig has its own syntax and coding standards.
Enabling Twig debugging is much easy in Drupal 8. Twig debugging helps developers easily find template names and theme_suggestions hook to create new template naming structures. Every Drupal 8 site comes with a default.services.yml file in the sites/default directory. Rename it to services.yml.
In that services.yml file there is a parameter called twig.config. Change the debug variable from false to true, But the auto_reload to true, and the cache variable to false are optional. Save and clear the cache.
And from txg/web/themes/custom/txg/templates/content/node--event--card.html.twig if there is a url, display the link with the url, otherwise just display the title for the link. I'm not 100% sure this is really valid. Can you put in a title and no link?
Although we do not have most of the features of PHP in twig, we do have a set of constructs for working with arrays and variables. For example, we can check if a variable exists before displaying this variable.
You can use twig for a lot of things. Making drupal components more industrial means you can pick up twig and just work with it rather than in D7 where you would need to learn the Drupal twig version.
df19127ead