Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Twig with FuelPHP
  • As suggested in another forum thread, I downloaded Twig and put that in app\vendor\Twig folder.

    I am following the link http://coderecho.com/how-to-activate-twig-in-fuelphp-1-5/

    Changed the controllers and view to use the twig.

        public function action_index() {
            return Response::forge(View::forge('install/index.twig'));
        }

    Enabled allways_load value in config.php file for 'parser'.

    But when I view the page, I get the below error.

    ErrorException [ Error ]: Class 'Twig_Autoloader' not found



    PKGPATH/parser/classes/view/twig.php @ line 31



    26    protected static $_twig_lexer_conf;
    27
    28    public static function _init()
    29    {
    30        parent::_init();
    31        Twig_Autoloader::register();
    32    }
    33
    34    protected function process_file($file_override false)
    35    {
    36        $file $file_override ?: $this->file_name;
    What I am missing in this?
  • You're supposed to use composer to install Twig, if you manually install it, the autoloader won't know where to find the Twig classes.
  • Well, I get the below issue when using composer to install Twig.

    Failed to clone http://github.com/fabpot/Twig.git, git was not found, check that it is installed and in your PATH env.

    I see there are many error reports for this in Google, but mostly related to Twig.
  • GIT is installed and added in my PATH (Windows XP)
  • I'm not familiar with Windows, so I can't help you out with this one.
  • What would be the solution if its on *nix ? I would do the same for Windows.

    Thanks.
  • Normally composer uses the packages available, unless you've defined * or something like dev-master for the version in your composer.json. To install a package you don't need git, they are zipfiles.

    On linux git is installed in /usr/bin, which is in the path and therefore composer just works.

    On Windows there are a lot of ways to install git, so it's difficult for me to judge (without even having a Windows system available) where it goes wrong. Most people I know use git bash, which gives you a bash (linux) commandline in Windows from which you can run the git binary and php commandline stuff.
  • You can also pop into our IRC channel (#fuelphp on Freenode), there are usually quite a few people online that use Windows for development.
  • This is the Git that you want for Windows, it will automatically add the path etc;


    Also make sure that you add the php path to your environment variables.

  • Hi Puru,

    i wrote this article and that was what i needed last time to do. But now with 1.7 i had also problems and now i am trying something else what should work. I also create new article how to install it. I wrote it now and published it when you don´t understand somethin tell me plz i will try to update the article.
  • Hi Webfacer,

    Thanks for the link. I was able to install twig using composer. It would be really good, if you could add to your docs, how to use twig template in FuelPHP. I am brand new user to fuelphp.

    BTW, sorry for the delay for my reply. I was involved in some other projects.

  • HarroHarro
    Accepted Answer
    From a FuelPHP point of view, it doesn't matter with template engine you use to render your views, they all work identical. Only the PHP engine itself is (obviously) included in the core, to add support for other engines you need to always_load the Parser package in your config.

    Once done, you can load and use a twig template exactly the same as any other view, only the extension differs.

    // load a default (=php) view
    $view = View::forge('some/viewname');
    $view = View::forge('some/viewname.php');

    // load a twig template view
    $view = View::forge('some/viewname.twig');
  • Thanks. I am now able to use TWIG.
  • I can´t use twig with just editing in the config file with just adding always_autoload -> packages -> parser

    i just copied a project from me that i used by a client where i used twig. When installing from existing it can´t find the twig_autoloader. after i am installing it with composer it works... why is that so. How to use twig now or  the parser autoloader?
  • The parser package requires you to install twig using composer.
  • oki now i got it thx @harro

Howdy, Stranger!

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

In this Discussion