You have M such media. Code reuse and refactoring. When I need to replicate code, I use calls to named templates, sometimes with parameters if there are slight variations that need to be accounted for. Named templates provide the equivalent of subroutines or private methods. The templates with the greater degree of specificity will have higher priority for matching.
Presentational data is data, too.
At some point, though, you have things that need to be dynamically generated, and for this my solution for now has been to just bite the bullet and write custom templates.