I worked for a client a number of years ago (who I won't name to protect the guilty) that would periodically have information like the following in their View logic:
if (client == "a") {
// ...
}
else if (client == "b") {
// ...
}
else {
// ...
}
Their platform was ColdFusion (yeah, don't laugh) and this was part of the template for their primary form process.
Obviously, this is cringe-worthy and terrible for numerous reasons.
I was recently thinking about how I would've architected that instead. My first thought was to use a Template Method pattern combined with either Dependency Injection or a Factory Pattern (to abstract away the client-specific reasoning) for the view in question.
Obviously, this solution assumes that you construct views on the "back end." This isn't really the "standard" way of doing this anymore, though, and most people seem to have switched to some kind of MVC architecture (ASP.NET MVC, Ruby on Rails, etc.). With that in mind, I did notice that ASP.NET Core includes support for Dependency Injection into views, as does MVC 4.
I'm hoping this isn't too simple of a question, but is what I describe above still valid way to solve this problem in MVC-based frameworks (especially ASP.NET MVC)? In particular, I'm confused about how to apply this to ASP.NET Views; I know that the Views support Dependency Injection, but is there some kind of analogy to a Template Method pattern for ASP.NET views that won't result in inappropriate mixing of business and view logic? Or am I on the wrong track here entirely?