
Originally Posted by
Ren
What if sub-component-x requires some javascript?
Assuming output buffering is being used (and I'd assume so, so that caching can be used) then each sub-view just has to register with either its parent or the root that it wants x chunk of HTML in the <head>. That piece of code could be a <script> tag, or a <link> to an RSS feed, or whatever you like.
It would probably be easiest to do this in the root rather than a parent, saves bubbling up the data. There is only one <head>, so there may as well only be one object to handle it, though if you don't want children knowing about root, you'll only have to tell them about parent. If parent asked its children for <head> info, the child wouldn't even need to know about its parent, in which case the parent my as well be root.
Code:
asks asks
root ====> parent ====> child
^ ^ |
| head | body |
| | |
+----<------+----<------+
body+head
===> = request
---> = data flow
head = a view which renders: <script>, <link>, <meta> etc
body = a view which renders: <h1>, <p>, <div>, <li> etc
bold = classes/nodes
And because of the infinite repitition, root is the parent of parent, just as parent is the parent of child, so eventually parent passes its body to root too.
Douglas
Bookmarks