vegas-cmf / core

Vegas CMF Core
MIT License
30 stars 7 forks source link

How to setup phtml #27

Closed raxan closed 9 years ago

raxan commented 9 years ago

Hi

how to setup to use phtml as template engine and not volt.

thanks

archdevil666pl commented 9 years ago

Volt works perfectly with embedding PHP & HTML code - there's no need to add any separate engine ;-)

If you want to use .phtml extension instead of .volt, add following snippet somewhere in the initialization process, after your view is registered:

\Phalcon\DI::getDefault()->get('view')->registerEngines([
    ".phtml" => 'Vegas\Mvc\View\Engine\Volt'
]);

In case you need a completely different approach, this guide might be useful: https://vegas-cmf.github.io/1.0/guide/mvc/view.html

raxan commented 9 years ago

Hi

thanks for your reply.

So basically if I use PHP on volt file, there is not any cache mechanism?

I want use directly PHP for best performance.

thanks

archdevil666pl commented 9 years ago

According to Phalcon docs: Volt views are compiled to pure PHP code. The PHP code you use inside a volt template is interpreted after being compiled to the target .php format.

Please look to your cache directory to have a better feeling about it ;-)

raxan commented 9 years ago

Yes, I see that is compiled in cache folder. However, first time page load (and after lifetime of cache expire), it's used volt.

raxan commented 9 years ago

Do you think there is not improvement in performance using phtml instaed of volt?

Usually PHP template engine it's most fast that others because there is not any layer between.

arius86 commented 9 years ago

Hi Raxan,

Vegas View class registers as default both phtml and volt engines. So if you want to use phtml, just do it, you don't need to register phtml or something.

Anyway, regardless the performance, volt templates (and other twig-like templates) are easier to maintain, cleaner and they are giving you some nice extra stuff like loop context. You can check this topic for more detailed informations: http://stackoverflow.com/questions/17778467/phalcon-volt-template-engine-why-use-it-and-what-are-the-benefits

Last but not least, please keep in mind that rendering volt is done by Phalcon in memory, so it's pretty fast. If you feel phtml better go with it. If you want to use it because of performance - it's just premature optimization :)

Cheers!

raxan commented 9 years ago

Thanks for your reply ! Very useful.

best regards