简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM