fuel / parser

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

View->set_filename() not working as expected #82

Closed dakorpar closed 9 years ago

dakorpar commented 10 years ago

If I have $this->view = View::forge(); and later I try to set filename like $this->view->set_filename("template.twig"); it will search for template.twig.php, but if I have $this->view = View::forge("dummy.twig"); later I can do $this->view->set_filename("template"); //notice that there's no .twig extension and everything will work as expected. I find this behavior littlebig strange.

WanWizard commented 10 years ago

It is because it doesn't work that way.

Without the parser extensions, or without requesting a specific partner extension, View::forge() returns a View object, which doesn't load the view file until the view is rendered. With the parser extensions, View::forge('dummy.twig') returns an instance of a View subclass, in this case View_Twig.

So when you do

$this->view = View::forge();
$this->view->set_filename("template.twig");

you're asking a View instance to convert itself to a View_Twig instance. Which isn't possible. What you can do is change the view file later to another view of the same type.

But

$this->view = View::forge("dummy.twig");
$this->view->set_filename("template.smarty");

will not work either, for the same reason.