Matt Stauffer has a post to his site showing you how to use custom conditionals with Blade, the templating engine for the popular Laravel framework.
One of the greatest aspects of Laravel Blade is that it's incredibly easy to handle view partials and control logic. I find myself frequently extracting the contents of a loop out to a Blade partial and then passing just a bit of data into the partial.But sometimes the repetitive code isn't the view itself, but the conditional logic I'm running.
He gives a practical example of an issue he had in some recent work he's done: a simple site for his physical trainer that needed to test for public vs non-public resources. The same evaluation code was being pasted all over the site so he looked for a better way. He introduces the idea of a custom directive in Blade and how they're converted to PHP out in the view. He shows how to make an @public
directive to replace his cut-and-paste logic from before and make the template much cleaner. He includes the code for this simple directive and ends the post with some other possible options use could use the directives for.