– Write Logic between the {%…%}, like, Conditions, Loop, Set variables values etc.
– EX:-
1. Set variable:-
{% set var_name = var_value %}
Now, print the variable:- {{ var_name }}
2. Conditions:-
{% if (a or b) %}
{% endif %}
3. Loop:-
{% for key in row %}
{{ key.value }}
{% endfor %}
* How to use Twig Functions in Drupal 8:-
1. file_url($uri)
– file_url funcion fetch the relative path of file from the root and generate the uri for file.
– Syntax :-
{{ file_url(content.file_machine_name.entity.uri.value) }}
– Ex:-
{{ file_url(content.field_middle_image.entity.uri.value) }}
– Write the function in img tag for displaying on the front. Like,
<img src="{{ file_url(content.field_middle_image.entity.uri.value) }}" />
– Fetch multiple files using file_url and fop loop:-
– Syntax:-[code]{% for item in content.file_machine_name[‘#items’] %}
{{ file_url(item.entity.uri.value) }}
{% endfor %}[code]
– Ex:-{% for item in content.field_middle_image['#items'] %}
<img src="{{ file_url(item.entity.uri.value) }}" />
{% endfor %}


2. link($text, $url, $attributes)
– link () function is used for the create link with attributes.
- $text: - Title of Link
- $url: - URL of link
- $attributes: - Add attributes like classes and name.
Syntax:-
- {{ link($text, $url, $attributes) }}
Ex:-
- {{ link(item.title, item.url, { 'class':['abc', 'def']} ) }}


Mainly, this function is used for the render menu in template.
3. path ($name, $parameters, $options)
4. url($name, $parameters, $options)