3

In my base template extended by all other templates, I import my macros, so I have global use of them throughout my templates.

Question 1: Am I taking a performance hit for including these whether or not I'm using them in a given template?

Question 2: Is there any advantage to splitting up macros into different imports, other than just organization?

In other words, is there any reason not to do:

{% import "_includes/macros" as macros %}

And have _includes/macros have all my macros?

2

This is definitely not a great answer, but I'm not sure anyone's going to be able to really answer this. You'd have to set up some sort of unit tests or something. And it will probably depend a lot on your server environment. But think of all the class files that need to get loaded just to handle a simple request. Personally, I think that the performance hit on an import statement is going to be pretty tiny regardless. I would opt for importing them in whatever way makes the most sense from a development/organizational perspective.

  • I agree, I'd imagine the performance hit to be negligible. Don't forget, Twig compiles down to PHP, and that PHP is then cached. So basically, you'll end up with a slightly larger-than-necessary PHP file, but it shouldn't really affect your performance overall. Moral of the story... your personal preference and sense of organization trumps any insignificant performance issues. – Lindsey D Dec 19 '14 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.