Declarative Blade Extensions
Update As Jeffrey points out in the comments, there's a much cleaner way of implementing this functionality (without extensions). I'm still interested in ways to manipulate Blade for producing 'DSLs', however.
In order to break looped output into sections, you may write something like the following in Laravel's Blade templating language:
This works, but it's pretty ugly. There's a pretty significant mental-processing step going on as you skim through it, which isn't great.
Blade allows us to register custom "extensions" to the compiler. Using these, we can produce a much more declarative syntax, which reads a lot like something you'd see in a Ruby library:
Personally I feel the readability of this is a huge bonus, as we're hiding the implementation details.
This syntax was implemented using the following extensions: