fuel / parser

Fuel PHP Framework - v1.x template parser package adapters
http://fuelphp.com
64 stars 45 forks source link

Need more Fuelphp classes and methods supports for Twig #65

Closed mrDlef closed 11 years ago

mrDlef commented 11 years ago

I solved that by extending the \Parser\Twig_Fuel_Extension classes but maybe there is a better solution to have an exhaustive set of functions :

<?php

class Twig_Fuel_Extension extends \Parser\Twig_Fuel_Extension
{
    public function getFunctions()
    {
        return array(
            'fuel_version' => new Twig_Function_Method($this, 'fuel_version'),
            'url'           => new Twig_Function_Method($this, 'url'),

            'uri_base'      => new Twig_Function_Function('Uri::base'),
            'uri_segment'   => new Twig_Function_Function('Uri::segment'),
            'uri_segments'  => new Twig_Function_Function('Uri::segments'),
            'config'        => new Twig_Function_Function('Config::get'),
            'lang'          => new Twig_Function_Function('Lang::get'),

            'form_open'     => new Twig_Function_Function('Form::open'),
            'form_close'    => new Twig_Function_Function('Form::close'),
            'form_input'    => new Twig_Function_Function('Form::input'),
            'form_password' => new Twig_Function_Function('Form::password'),
            'form_hidden'   => new Twig_Function_Function('Form::hidden'),
            'form_radio'    => new Twig_Function_Function('Form::radio'),
            'form_checkbox' => new Twig_Function_Function('Form::checkbox'),
            'form_textarea' => new Twig_Function_Function('Form::textarea'),
            'form_file'     => new Twig_Function_Function('Form::file'),
            'form_button'   => new Twig_Function_Function('Form::button'),
            'form_reset'    => new Twig_Function_Function('Form::reset'),
            'form_submit'   => new Twig_Function_Function('Form::submit'),
            'form_select'   => new Twig_Function_Function('Form::select'),
            'form_label'    => new Twig_Function_Function('Form::label'),
            'form_val'      => new Twig_Function_Function('Input::param'),

            'asset_add_path' => new Twig_Function_Function('Asset::add_path'),
            'asset_css'     => new Twig_Function_Function('Asset::css'),
            'asset_js'      => new Twig_Function_Function('Asset::js'),
            'asset_img'     => new Twig_Function_Function('Asset::img'),
            'asset_render'  => new Twig_Function_Function('Asset::render'),

            'html_anchor'   => new Twig_Function_Function('Html::anchor'),

            'input_get'   => new Twig_Function_Function('Input::get'),
            'input_post'   => new Twig_Function_Function('Input::post'),

            'session_get_flash'   => new Twig_Function_Function('Session::get_flash')
        );
    }

    public function fuel_version()
    {
        return Fuel::VERSION;
    }
}
mrDlef commented 11 years ago

Thanks :)