php - Acces legacy class from twig view -
we re-writing part of web portal , need bitwise compare in twig view. have value(integer) in view passed controller , need make decision on image display. used bitwise compare against values in class somewhere in /opt folder.
i can bitwise (b-and) compare in twig how access legacy php class comparison?
within twig template don't have access regular php methods. so, include legacy class, need write custom function , twig extension. here example:
class stepoutextension extends \twig_extension { public function getfunctions() { return array( 'inspect' => new \twig_function_method($this, 'step_out', array('needs_context' => true)) ); } public function stepout($context) { // access class here } public function getname() { return 'legacy_class'; } }
and register service:
services: my_namespace.step_out: class: acme\demobundle\extensions\stepoutextension tags: - { name: twig.extension }
within twig can call new function
{{ step_out() }}
more details can found in symfony docs.
Comments
Post a Comment