At the top of classy's page-title.html.twig docs there are variables available by default. The variable {{ title }} will print the entity's title field value. "The page title, for use in the actual content." For example:
{% Do Something %}
The `
syntax is for code syntax. From the above/core/themes/classy/templates/content/page-title.html.twig example.The
` uses the if statement to only print a page title if there is a value.
The `
` can also be used to extend templates.
For example, extend page-title.html.twig would use the original twig template as its base.
{#Comment on Something# }
Use the {# #} syntax for comments and documentation.
Why Twig?
Changing the template engine to use twig helps separate the concerns of functional business logic and the presentation markup. Twig auto-escapes and sanitizes HTML to prevent XRSF attacks. Twig Syntax replaces the use of print() and render()
For example, if you want to join several strings together you can use the safe_join filter. For Example"
This will print the items value concatenated together with a comma separating each item. Although filters and twig come from the Symfony integration, there are Drupal specific filters which are located at Drupal specific filters are declared in Drupal\Core\Template\TwigExtension::getFilters()
BLT can validate twig errors with blt validate:twig
{{ Say Something }}
{% Do Something %}
{# Comment on Something #}
{#
/**
* @file
* Theme override for page titles.
*
* Available variables:
* - title_attributes: HTML attributes for the page title element.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title: The page title, for use in the actual content.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
*/
#}
{{ title_prefix }}
{% if title %}
<h1{{ title_attributes.addClass('page-title') }}>{{ title }}</h1>
{% endif %}
{{ title_suffix }}
{% extends "page-title.html.twig" %}
{#
/**
* @file
* Theme override for page titles.
*
* Available variables:
* - title_attributes: HTML attributes for the page title element.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title: The page title, for use in the actual content.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
*/
#}