kwattro/KDBParametersBundle — Issue #3: twig extension for parameters
Author: Sergic
Created: 2012-02-11 13:36:49+00:00
State: open

propose you to add twig extension for getting parameter from template
in service.yml

kdb_parameters.twig.extension:
class: KDB\ParametersBundle\Twig\Extension\KDBExtension
arguments: [@kparams]
tags:
- { name: twig.extension }

create KDBExtension.php

KDBService = $KDBService;
}

/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'kdb_parameters';
}

public function getFunctions()
{
return array(
'kparam' => new \Twig_Function_Method($this, 'kparam')
);
}

/**
* @param string $param
* @param string $default
* @return string
*/
public function kparam($param, $default = null)
{
$parameters = $this->getKDBService();
return $parameters->getParam($param, $default);
}

/**
* @return \KDB\ParametersBundle\Util\ParameterManipulator
*/
public function getKDBService()
{
return $this->KDBService;
}
}

///
in twig template we can use function kparam
{{ kparam ('company_name', 'Light Slide') }}