In modern web frameworks like Rails and symfony the concept of partial includes or partial views is well documented and recommended.
What I am having trouble with lately is deciding how much design to include in the partial.
It's kind of hard to explain but I want to know what others do when creating a partial and including it in a template. Do you only display the data and position it in the template or do you put all the styling and positioning code in the partial and just include it like so.
I guess my question is, what is your thought process when deciding to create a partial and when do you use it in your own code, and how much do you put into your partial when you decide to use one.
I use partials for pieces of view code that are used in more than one place. If the code is going to be duplicated or re-used in several places, then it is a prime candidate to be DRY'd up and placed into a partial.
As far as styling code, all that should reside in your CSS files
If you're repeating parts of your view code, a partial is a good idea. If the code you're reusing is a little different between your pages, make use of the parameters you can pass the partial.
As for the CSS, I'd suggest keeping it outside your partial/template. If you have a lot of partial specific CSS code, create a "partials" folder under web/css and name the css files to match your partials (If you think the overhead is worth the organization).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With