I know how to add custom fields to pages just fine. However, I would like my meta box to only appear once the user has selected the template “Foo” (filname “foo.php”). I have jQuery loaded on the admin section but I have had no luck in trying to add a custom class to the container that holds the meta box.
Note: I do not want to select by the ID of the meta box div because there are going to be several hidden meta boxes and I will have no way of hiding all of them at once without a class assigned (hence my problem).
This is not a complete solution, but might get you started in the right direction:
In the code which are displaying the meta box, you can use the get_post_meta function to get information about which template the current page is using. Something like this:
The downside of this is that the user must choose template first, then save the page once in order to make the admin page reload with the right settings.
Otherwise I think the solution you describe using jQuery somehow to hide the meta boxes is the best way to do it.
Good luck
My solution to this was to create a div in each custom meta box and then use jquery to hide all of the parent elements of those divs.