Вопрос

In the fatfree framework, I am trying to write a function which can spit out minified css/js and call it from within the template htm. But it seems as soon as I try to call the function from with the htm, the entire page is rendered as text, including the doctype and all tags.

My controller simply has:

public function index($f3, $params) {
            echo \Template::instance()->render($this->BM->themeAbsPath('user_group.htm'));
    }

In the .htm template I have:

<style>
{{ @BM->minify('css','css/',array(
                                    'bootstrap-theme.min.css',
                                    'main.css',
                                    'vendor/smartmenus-0.9.5/addons/bootstrap/jquery.smartmenus.bootstrap.css',
                                    'vendor/datatables/css/jquery.dataTables.css',
                                    'vendor/datatables/css/jquery.dataTables_themeroller.css'
                                )) }}
</style>

And lastly the function:

public function minify($type='css',$folderpath='css/',$files=array()){
        $filepaths = implode(",",$files);
        $this->f3->set('UI',$this->themeRelFolder().'/'.$folderpath); 
        $this->f3->set('minified_'.$type,\Web::instance()->minify($filepaths));
            return $this->f3->get('minified_'.$type);
    }

I am not getting any 500 errors or such, so what am I doing wrong?

Это было полезно?

Решение

By default the Web->minify function sends a Content-Type HTTP header. In order to prevent this behaviour, you should set the third parameter to FALSE:

\Web::instance()->minify($filepaths,NULL,FALSE)

NB: the complete function signature is:

minify ( string|array $files [, string $mime = NULL [, bool $header = TRUE ]] )
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top