1

can any one suggest how to access class static property from the twig template ?

Lets say i have

class Foo {

    const KEY_1 = 1;
    const KEY_2 = 2;

    const VAL_1 = 'HELLO 1';
    const VAL_2 = 'HELLO 2';

    public static $bar = array(
        self::KEY_1 => self::VAL_1,
        self::KEY_2 => self::VAL_2,
    );

}

then i transfer this class to the template like

$template->render(array('Foo' => new Foo() ))

now, how i can access the static property from the twig template like

{{ Foo.bar.constant('Foo::KEY_1') }}

smth like this or any other way ... it looks to me that i tried all possible ways :(

Eugene
  • 1,680
  • 3
  • 14
  • 23
  • Look at this : http://stackoverflow.com/questions/7611086/how-to-access-class-constants-in-twig – Pierrito Jul 29 '13 at 14:49
  • i can access constants, BUT i CAN NOT access static properties ... if im trying to access `constant('Foo::bar')` im receiving error **Warning: constant(): Couldn't find constant Foo::bar** – Eugene Jul 29 '13 at 14:52
  • so this -> http://stackoverflow.com/questions/6844266/twig-template-engine-using-a-static-function-or-variable – Pierrito Jul 29 '13 at 14:55
  • yep, i read that, there injection for the method but not a problem to write for a property, BUT i thought may be exists built in standard way without extending twig :( may be so obvious that i just miss it :) – Eugene Jul 29 '13 at 15:04
  • 2
    at the moment solved by having getter method inside Foo class up to me it is better than extending twig ... PS: how to close issue/mark it solved ? – Eugene Aug 05 '13 at 11:24
  • 1
    @Eugene write yours solution as a question answer and mark it (You'll have to wait 24h to be able to mark it as solved) – canni Sep 16 '13 at 09:41

0 Answers0