Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partials vs for loop — best practices

In coding up your view templates you can render a partial and pass an array of objects to be rendered once per object. OR you can use a For blank in @blank loop. How do you decide when to do which? It seems that if you use a partial for every iterable object you will end up having to modify tons of separate files to make changes to potentially one view. With the loops you can see everything right there in one file.

like image 542
Michael Avatar asked Jun 17 '26 18:06

Michael


1 Answers

Generally I only use a partial for an individual object when I need to render that single object somewhere else, like in an RJS view. It keeps the views a bit easier to follow, in my opinion.

like image 97
Robert Speicher Avatar answered Jun 19 '26 13:06

Robert Speicher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!