Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.
/ twig_reflection Public archive

A Twig extension in order to access directly static methods and attributes of a class

Notifications You must be signed in to change notification settings

enrico69/twig_reflection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

twig_reflection

Objectives

This Twig extension allows to access public static attributes and methods of a class.

Installation

  1. Copy the file Reflection.php in the Twig/Extension directory of your Bundle/Module.
  2. Declare the extension. For example in Symfony 2/3, you have to do it in the app/config/services.yml :
site.twig.reflectionExtension:
        class: AppBundle\Twig\Extension\Reflection
        tags:
            - { name: twig.extension } 

Utilization

There are two methods callable in this extension :

* callStaticMethod($className, $methodName, array $args = [])
* getStaticAttribute($className, $attributeName)

From your Twig template, just call the good one with the proper parameters, for example:

set arrType = getStaticAttribute('AppBundle\\Entity\\Book', 'arrSearchTypes')

About

A Twig extension in order to access directly static methods and attributes of a class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages