Access static variable in symfony 2.2 twig

Floricel picture Floricel · Apr 14, 2013 · Viewed 11k times · Source

I have a class containing constant options in array form:

namespace MyNameSpace;

class OptionConstants
{
  /**
   * Gender options
   */
   public static $GENDER = array(
    'Male',
    'Female'
   );

  /**
   * University year levels
   */
   public static $UNVERSITY_STANDING = array(
    '--None--',
    'First Year',
    'Second Year',
    'Third Year',
    'Fourth Year',
    'Graduate Student',
    'Graduated',
    'Other'
   );
}

How can I access $UNVERSITY_STANDING or $GENDER in symfony 2.2 twig?

Answer

Marino Di Clemente picture Marino Di Clemente · Apr 15, 2013

just call constant function

{{ constant('Namespace\\Classname::CONSTANT_NAME') }}