+# See also parse_template and fill_template.
+
+
+# To track our position in the template and in the data, we use a linked
+# stack structure. Each node is a hash with a reference to the parent
+# node along with whatever other data you want to add. For each stack,
+# you simply keep a variable with a reference to the top element. Then
+# the push and pop operations are:
+
+# $top =& tem_push($top);
+# $top =& $top['parent'];
+
+function &tem_push(&$stack = NULL) {
+ static $refs = array();
+
+ # Since a PHP reference is *not* a pointer to data, but a pointer to
+ # a variable (or array slot), we *have* to first put the new node in
+ # $refs, and then reference it from $new.
+
+ $refs[] = array();
+ $new =& $refs[count($refs)-1];
+ if($stack) $new['parent'] =& $stack;
+ return $new;
+}
+
+