Template variables

Drupal 8 uses variables to output data within Twig templates. We know that variables generally consist of anything from a simple string to a complex object containing an array of values. If we look at the html.html.twig template, we will see documentation that outlines the variables available to us along with the name of the variable and a description of what the variable contains:

Variables:
 logged_in: A flag indicating if user is logged in.
 root_path: The root path of the current page (e.g., node, admin, user).
 node_type: The content type for the current node, if the page is a node.
 head_title: List of text elements that make up the head_title variable.
   May contain or more of the following:
   - title: The title of the page.
   - name: The name of the site.
   - slogan: The slogan of the site.
   - page_top: Initial rendered markup. This should be printed before 'page'.
   - page: The rendered page markup.
   - page_bottom: Closing rendered markup. This variable should be printed after 'page'.
   - db_offline: A flag indicating if the database is offline.
   - placeholder_token: The token for generating head, css, js and js-bottom placeholders.

Each of the variables that our template has access to can be output using Twig syntax. For example, the head_title variable outputs the title of our page within the <title> element. Drupal also uses {{ attributes }} to print out additional information to our page, for example, the <body> element to output CSS classes needed by modules or themes.

Each template we will work with uses variables to output database content. What if we want to add additional variables to Drupal? This is where the role of the theme file comes into use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.172.115