Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel Parser.
  • Hey guys, well I have been using Laravel for a while, and decided to give FuelPHP a shot again.  I had worked with it in previous but never really fully developed anything with it.  Well I would like to do that now, however I'm trying to use the parser.  So I downloaded PycroCMS/lex as the template engine, (also tried twig).  Copied the parser.php to the app/config, enabled the packages to the auto load packages, and in the Presenter for the default hello, I put in


    protected $_view = 'welcome/hi.lex';

    and changed the information in the hello.php that was in the app/views, to {{ name }} however I get a error when trying to load the view. 

    Fuel\Core\FuelException [ Error ]:
    The requested view could not be found: welcome/hi.lex


    Which I don't really get because the parser is loading, and the view is there with the .lex extension.  I also did this with twig, and got it to work but it seemed twig stripped the html out of the layout and the design had no css or anything.   Any ideas?  Hope this makes since.


    **Update I have fixed the issue with the loading and viewing the view.  It was my issue, i didn't uncomment the autoload in config.  Disregard this post, you can delete it if you want.  I failed to update the asset::css too twig also.  So it should have been {{ asset_css('whatever.css') }}

  • I will also say that I installed lex and twig with composer...
  • Sorry had a type also the protected $_view = 'welcome/hello.lex'; should be protected $_view = 'welcome/hi.lex';
  • HarroHarro
    Accepted Answer
    Does that mean it works now?
  • Ah yes, I guess its a bit confusing I found the edit button at the last moment.  Everything is working, the twig is anyways, the css was my issue too I didn't wrap it around the {{}} instead it was still <?php ?>.  The lex is still coming up stating that the view file doesn't exist but as long as the .twig extension is working that is what i needed.   Thanks!
  • HarroHarro
    Accepted Answer
    Try switching the Parser package to 1.8/develop.

    I've seen there were some Lex fixes after the release of 1.7.2, perhaps someone else bumped into this issue to?
  • Updating to the parser 1.8 and lex is also working now.

    New parser seems to fix the issues with the lex, and its working with twig also.  Question for you, how do I make twig take the .tpl extension instead of twig?  Now a big deal but would be nice to do .tpl.  I know it is in the parser conf, I did try to update it so listen to the .tpl but it didn't work, so I'm assuming I'm doing something wrong there.
  • In the config file. The default is

        'extensions' => array(
            'twig'      => 'View_Twig',
            'mthaml'    =>  array('class' => 'View_HamlTwig', 'extension' => 'twig'),
            'mustache'  => 'View_Mustache',
            'md'        => 'View_Markdown',
            'dwoo'      => array('class' => 'View_Dwoo', 'extension' => 'tpl'),
            'jade'      => 'View_Jade',
            'haml'      => 'View_Haml',
            'smarty'    => 'View_Smarty',
            'phptal'    => 'View_Phptal',
            'lex'       => 'View_Lex',
        ),

    meaning the '.tpl' extension is assigned to Dwoo.

    So you have to add a parser.php config file to your app, and put in it:

    return array(
        'extensions' => array(
            'twig'        => array('class' => 'View_Twig, 'extension' => 'tpl'),
            'dwoo'      => array('class' => 'View_Dwoo', 'extension' => 'dwoo'),
    );

    to override the default.
  • Okay that is what I thought and how I have been doing it, I have done that again and now I get {{ name }} instead instead of "World" or the name that you put after /hello/userdefined.   Copy parser.php to /app/config and it is as follows:

    'extensions' => array(
    'php'       => 'View',
    'twig'      => array('class' => 'View_Twig', 'extension' => 'tpl'),
    'mthaml'    =>  array('class' => 'View_HamlTwig', 'extension' => 'haml'),
    'mustache'  => 'View_Mustache',
    'md'        => 'View_Markdown',
    'dwoo'      => array('class' => 'View_Dwoo', 'extension' => 'dwoo'),
    'jade'      => 'View_Jade',
    'haml'      => 'View_Haml',
    'smarty'    => 'View_Smarty',
    'phptal'    => 'View_Phptal',
    'lex'       => 'View_Lex',
    ),
  • Just for my understanding:
    - you added the above in app/config/parser.php
    - you have copied app/views/welcome/hello.php to app/views/welcome/hello.twig
    - changed the "echo $name" to "{{ name }}"
    - changed app/classes/controller/welcome.php, action_hello, to forge('welcome/hello.twig")

    correct?
  • Twig works, however if I change it to .tpl it doesn't parse the {{ name }}.  But i have done everything you have stated above the only difference that I did was put protected $_view = 'welcome/hello.tpl'; in the presenter of welcome.php in /app/classes/presenter/welcome/hello.php

    So it is like the parser.php config file, isn't taking the new extension instead using and keeping .twig for the twig template engine.
  • I've added a fix to both the core View class and the Parser package, so if you both update to the latest 1.8/develop, Twig should work as advertised.

Howdy, Stranger!

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

In this Discussion