I have two twig extensions and a twig. I need functions from both the twig extensions in one twig. What is the way to differentiate that from which extension the function is called.
Right now, I'm using this method driverId|getDriverNameFromId
and it is giving me error!
Below is the code for driver extension:
<?php
namespace abc\CoreBundle\Extension;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use abc\CoreBundle\Entity\CostAllocation;
use abc\CoreBundle\Entity\Driver;
class DriverExtension extends \Twig_Extension {
protected $mr;
protected $container;
public function __construct(ManagerRegistry $mr, Container $container)
{
$this->mr = $mr;
$this->container = $container;
}
public function getFilters()
{
return array(
new \Twig_SimpleFilter('getDriverNameFromId', array($this, 'getDriverNameFromId')),
);
}
public function getName()
{
return 'driver_extension';
}
/**
* get updated columns
*
* @param Integer $driverImportId
*
* return array
*/
public function getDriverNameFromId($driverImportId)
{
return $this->container->get('core_process_import')->getName($driverImportId, 'DriverImport');
}
}
And similarly I have a core extension.
In my twig, when I call
{% if driverImport.id|getDriverNameFromId|length > 0 %}
{% endif %}
It gives me error
Unknown "getDriverNameFromId" filter in CoreBundle:DriverImport:list.html.twig at line 88?
Below is the code for services.yml
_core.services.invoice.extension.class: abc\CoreBundle\Extension\InvoiceExtension
_core.services.driver.extension.class: abc\CoreBundle\Extension\DriverExtension
invoice.twig.extension:
class: %_core.services.invoice.extension.class%
arguments: [@doctrine, @service_container]
tags:
- { name: twig.extension }
driver.twig.extension:
class: %_core.services.driver.extension.class%
arguments: [@doctrine, @service_container]
tags:
- { name: twig.extension }
DriverExtensionissn't loaded at all, and thus the filter is not available.