{% block header %} {% include "blocks/header.twig" %" /> {% block header %} {% include "blocks/header.twig" %" /> {% block header %} {% include "blocks/header.twig" %"/>

How to pass in data to a specific twig component?

24 Views Asked by At

I have a base twig template that most pages extend from like so:

<!DOCTYPE html>
<html lang="en">
{% block header %}
    {% include "blocks/header.twig" %}
{% endblock %}
<body>
{% block nav %}
    {% include "blocks/nav.twig" %}
{% endblock %}

{% block body %}

{% endblock %}


{% block footer %}
    {% include "blocks/header.twig" %}
{% endblock %}
</body>
</html>

I'm including a navbar that I want to conditionally change based on if a user is logged in. With just PHP templating, I would just use an autoloaded function to do this

if (loggedIn())
{
  echo "Some navbar link"
}

However I can't use this function directly into twig so I assume I would have to pass the result of this function (a bool). But I'm not sure how I can pass it down multiple layers, since for example most pages will use the base template, which uses the nav block. It would be a pain to have to pass it down every single time.

0

There are 0 best solutions below