Most PHP MVC systems follow a pattern where a request is routed to a specific controller action, and then the controller sets a bunch of variables for use in the view.
When you're in an agency/services work environment that uses a lot of dynamic HTML for UI elements, this patterns leads to a lot of javascript being generated with view variables
<script type="text/javascript">
jQuery(document).ready(function(){
$('#ui-element).init(
{
'param1':<?=$this->param1;?>,
'param2':<?=$this->param2;?>,
}
);
});
</script>
While this works, I've found it leads to views with a horrible spaghetti mix of HTML, PHP and Javascript. It also offends a certain class of front-end developer who thinks all javascript should be included in external files.
So, what are your patterns/practices to deal with this problem? Specifically, when you want to provide a default set of data for a Javascript widget in a PHP MVC framework, how do you do it while keeping things clean and modular? Is it just a matter of discipline, or are there specific design patterns that can force modularity** here, while still giving talented client-side developers a markup centric environment to work in.