phpfat-free-framework

How to use class->function() in fatfreeframework template


I have a class as below.

class myClass {

    //Strip string
    function strip($str) {
        return $str;
    }
}

In my code, I call the template as below.

echo \Template::instance()->render('admin/settings.html');

Now how do I apply class function to a variable in the template? What I want to do is something like this.

{{ myClass->strip((@value['setting__Setting'])) }}

This does not actually work.


Solution

  • Use static function?

    <?php
    class myClass {
    
        //Strip string
        public static function strip($str) {
            return $str;
        }
    }
    

    Call static function in template:

    {{ \myClass::strip((@value['setting__Setting'])) }}