1

We all know that for a customs web designing issue there are many solutions and various methods and ways, but this question has always existed, i.e about what the advantages/disadvantages (pros/cons) of each of them are.

For example, by using hook_preprocess in the theme file we can add our desired styles to custom blocks or regions, and reduce our needs to keeping multiple twig templates compared to times we use twig template to add our styles.

I want to be able to use those criteria (pros/cons) to decide which one is recommended in specific situations by considering indicators such as:

  • Stability
  • Efficiency and Loading speed
  • Maintenance
5
  • to avoid your question gets closed (opinion based), replace best/better by what are the pros/cons of each of them ... – Pierre.Vriens Jul 14 '17 at 20:40
  • Please check my attempt to make it a less "opinion based" question. Feel free to refine/correct if needed, or just perform a rollback if you don't like it at all (just trying to help ...). Good luck! – Pierre.Vriens Jul 14 '17 at 20:57
  • @Pierre.Vriens: Great, Thank you so much, I appreciate you hearty and a lot for your help ;-). – Mojtaba Reyhani Jul 14 '17 at 21:01
  • You're welcome! Just wanted to help to avoid the question gets closed (let's hope the refinement was sufficient to prevent that from happening). – Pierre.Vriens Jul 14 '17 at 21:04
  • @Pierre.Vriens: I would be very happy to know your opinion about this matter. and share your experiences about it. Thanks. – Mojtaba Reyhani Jul 16 '17 at 6:10
3

It's not really an either/or thing. They are used together - preprocess functions are run before a template is used. Templates should only have very simple logic, if/else, and loops for the most part. Any logic more complex than this should go into a preprocess function. If you want to do things like adding classes to the attributes of a variable, this should generally be done in the preprocess function, though if you have a class that will only go in a single template, then it can be done in the template itself.

2
  • 2
    This is one point of view. Another one you can see in the core classy theme, which adds all classes (and these are a lot of classes) in twig templates. – 4k4 Jul 15 '17 at 7:39
  • Thank you so much, But I think to insist on twig templating can increase the number of useless twig files, and this matter by itself can reduce the performance and loading speed. for example, see this link: Is it possible to combine several template files together and make single integrated template instead? most of the twig templates files have the ability to control small pieces of content only like just a title. – Mojtaba Reyhani Jul 16 '17 at 13: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.