Personally, I like the way Drupal handles all template issues:
- /**
- * @file
- * Default theme implementation for comments.
- *
- * Available variables:
- * - $author: Comment author. Can be link or plain text.
- * - $content: An array of comment items. Use render($content) to print them all, or
- * print a subset such as render($content['field_example']). Use
- * hide($content['field_example']) to temporarily suppress the printing of a
- * given element.
- * - $created: Formatted date and time for when the comment was created.
- * Preprocess functions can reformat it by calling format_date() with the
- * desired parameters on the $comment->created variable.
- * - $changed: Formatted date and time for when the comment was last changed.
....
It's much cleaner code wise to use variables and not arrays or objects. The nice thing is that it is easy to do so with arrays, just use extract:
// Set up local data
extract($displayData);
Since the layout/template is being executed from within an object method, all the variables will be scoped to that method - not globally - and thus removed when the method ends.
As an added plus, if you stick to very basic PHP functions in templates/layouts than you can use the same templates in PHP and Javascript.