We have a Symfony 3.4 project with twig templates and authentication system by FOSUserBundle.
It is multi-domain and manages customer and supplier data mainly works well but now I have a problem that I do not know how to solve at the time of user registration.
I need that depending on the domain, it can show one or another twig template at the time of registration.
Search documentation and find how to write custom twig extension https://symfony.com/doc/3.4/templating/twig_extension.html
This is my function and almost like the one in the example
<?php
// src/AppBundle/Twig/AppExtension.php
namespace AppBundle\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class AppExtension extends AbstractExtension
{
public function getFunctions()
{
return [
new TwigFunction('server', [$this, 'serverName']),
];
}
public function calculateArea(int $width, int $length)
{
return $width * $length;
}
public function serverName()
{
$serverName = "$_SERVER[SERVER_NAME]";
return $serverName;
}
}
The question is, how can I use my function in Twig? I need that based on the domain in which it connects, it showed us a registration form or something like this:
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% if serverName == "xxxxx"%}
{% include "@FOSUser/Registration/register_content_cliente.html.twig" %}
{% else %}
{% include "@FOSUser/Registration/register_content_proveedor.html.twig" %}
{% endif %}
{% endblock fos_user_content %}
It does not work like that:
{{ serverName }}
{{ server }}
{% serverName %}
{% server %}