We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

VOLT - best practice for speed

I just have a quick question. I'm designing my views with Volt right now. It is very flexible with the ways you can include other views. But I want to be smart about the way I am designing and coding my views so that I can get the best performance.

Is it best to extend parent volt files, include volt files, or partially render other views? If so, why?

Thanks for your help.



8.6k

If you bother about template performance...you should bother about the real problems first. And if everything else is up and running great - and your wife is happy, and your kids too - then you could eventually think about template performance. That's my opition. And please don't ask about the why.

Apologies, but that doesn't answer my question.

I'm glad it is not of importance to you. But I'm about to spend a lot of time making templates in VOLT, and I'd like to make sure I go about it in a smart way. Meaning I won't need to redesign in the future. The documentation on these is particularly sparse. I'd love to hear from someone that has had experience with this and has any recommendations or has seen any problems by choosing a specific method. I think it is very valid to ask why someone would recommend a particular method.

I know that in Smarty you can actually get a decent performance boost by using template inheritance with extend vs. simply including different templates.

I was wondering if there was a similar situation with Volt, as this is a new template engine to me.



98.9k

Template inheritance creates a single php file processing blocks. Using partials it requires processed templates in different files. Performance improvement is relative to the operations you made in the templates not to the inclusion of the files themselves, if you're using a bytecode cache like opcache you wouldn't have any major concern regarding file inclusions.

Thank you for that reply. I have a follow up question then about include vs partial.

In the documentation it states...

‘include’ has a special behavior that will help us improve performance a bit when using Volt, if you specify the extension when including the file and it exists when the template is compiled, Volt can inline the contents of the template in the parent template where it’s included.

Would it be safe for me to assume that include is the better option in all cases?



98.9k
Accepted
answer
edited Jan '15

If you're using more than one template engine, using "include" will for sure reduce the number of stats made by the application, if you're using just Volt, any of those options will work the same.

Thank you for your time, I really appreciate it.