To perform this action you must create an extension that must be located in AppBundle / Twig / NombrediaExtension.php with the following code:
<?php
namespace AppBundle\Twig;
//Extension que saca el nombre del dia
class NombreDiaExtension extends \Twig_Extension
{
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('nombre_dia', array($this, 'nombre_dia')),
);
}
public function getName()
{
return 'nombre_dia_extension';
}
public function nombre_dia($nombredia)
{
$dias = array('','Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');
$fecha = $dias[date('N', strtotime($nombredia))];
return $fecha;
}
}
After this we must place the following code inside: app / config / services.yml
services:
#service_name:
# class: AppBundle\Directory\ClassName
# arguments: ['@another_service_name', 'plain_value', '%parameter_name%']
app.twig_extension.nombre_dia_extension:
class: AppBundle\Twig\NombreDiaExtension
tags:
- { name: twig.extension }
Finally in the twig file that we are using we make one of this function:
{% set diasemana = nombre_dia(datos.DueDate|date("Y-m-d")) %}
{{diasemana }}
Greetings