Answer the question
In order to leave comments, you need to log in
How to pass different variables to different blocks in TWIG?
Let's say I have base.html.twig in which there are several blocks: head, breadcrumbs and the main content.
When I render a template (base or one that inherits base), I can pass all the variables I have to the template and they will all be visible in all blocks.
Is it possible to make it so that when rendering, determine which block which variables go to? So that some variables are visible only in one block and in no other.
Example, this would be base
<!DOCTYPE html>
<html>
<head>
<!-- Тут просто какой-то код -->
</head>
<body>
<!-- Тут, допустим, хлебные крошки -->
{% block breadcrumbs %}
{% for breadcrumb in breadcrumbs %}
<a href="{{ breadcrumb.link }}">{{ breadcrumb.title }}</a>
{% endfor %}
{% endblock %}
<!-- Тут основной блок: -->
{% block content %}{% endblock %}
</body>
</html>
{% extends "base.twig" %}
{% block content %}
<!-- Тут контент основного блока -->
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question