Search code examples
phparraysclasssmarty

Using php class property in smarty template


Can i use php class static properties in smarty template? For example:

class UserData
{
    const INDEX = 1;
    const STREET = 2;

    static public $_address_fields = array(
        self::INDEX,
        self::STREET 
    );
}

And in my smarty template i want do something like this:

{UserData::$_address_fields}

Is it possible?


Solution

  • You can pass this in from your controller

    For example: $smarty->assign('AddressFields, UserData::$_address_fields);

    This should then be available for use in your template like so: {$AddressFields}

    Smarty Docs: https://www.smarty.net/docsv2/en/api.assign.tpl