Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Html Class in smarty or twig
  • is there a way to use Html Class (http://docs.fuelphp.com/classes/html.html) in smarty or twig templates?
  • For smarty I think you can use {php} tag and so put whatever you want inside ( like echo Html::method(); ) I rather use twig now for best performance. In this case and if you use fuelPHP v1.2 there is already an extension who manages some functions from template, look at the file /packages/parser/classes/twig/fuel/extension.php It manages some of useful function from view (Form, Asset, ...) but Html is not preset actually, but it's a piece of cake to add them.
    Example : 'form_open' => new Twig_Function_Function('Form::open'), means that you just have to use a twig tag like this {{ form_open() }} in order to call Form::open()
  • I made a modification of the twig extension to make it work with any static call :
    - copy (or add bold parts) this code in /packages/parser/classes/twig/fuel/extension.php
    <?php
    namespace Parser;
    
    use Router;
    use Uri;
    use Twig_Extension;
    use Twig_Function_Function;
    use Twig_Function_Method;
    
    class Twig_Fuel_Extension extends Twig_Extension
    {
     public function getName()
     {
      return 'fuel';
     }
    
     public function getFunctions()
     {
      return array(
       [b]'fuel_*_*'     => new Twig_Function_Method($this, 'call_static_method'),[/b]
      );
     }
    [b]
     public function call_static_method($object, $method)
     {
      $args = func_get_args();
      array_shift($args);
      array_shift($args);
      return call_user_func_array(array($object, $method), $args);
     }
    [/b]
    }
    

    Usage in twig template :
    {{ fuel_Form_open() }}
    is same thing that
    <?php echo Form::open(); ?>

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion