Twig is a flexible template engine for PHP. In Drupal Twig is using as default template engine. Twig is flexible, fast, and secure. Here we are going to discuss how we can integrate twig in Drupal 8. We will go through how to use twig template and how we can add new template for a block.
Blog
It has been three years since Drupal 8 is released. Even Drupal community has providing seamless support through forum and other resources(eg: IRC) still people are struggling during D8 development. So I'm sharing my D8 development experience here.
Majority will agree that most difficult part in Drupal development is theming. As Drupal is rendering html with its own containers and attributes achieving the exact design provided by UI developers in Drupal feels like a challenge to the developers.
Drupal 8 has made lot of improvements from Drupal 7. There are some bigger API changes and have incorporated with many good practices in the website development.
In drupal 8 we can use hasPermission() method to check user permission.
When a user register or edit own account details he can upload an image or photo of themselves, also known as an avatar. In drupal you can configure it in an easy manner with the help of contributed module.
You may know how to define custom permission in drupal 7. We were using hook_permission() inside *.module file like below...
In drupal 8 it's quite easy to create tabs in admin configuration pages. Instead of writing junk of codes we can do it easily by define settings inside a simple YML config file.
In drupal 8 you can get current logged in users info by using currentUser() method. If you want to use it in module file or other than a class you can call this method like below...
It may feel crazy to build a module without module file in drupal. But in drupal 8 it is possible. Which means module file is not a mandatory entity in drupal. Instead of writing everything inside module file drupal 8 will make your code more structured by using classes and objects.
Today we are going to create a smile module which creates a sample page using custom menu callback.
First let us list down the steps to create this module in drupal 7: