Planning and Developing the Core Framework foreach( $bits as $tag = $template ) { $templateContent = file_get_contents( $template ); $newContent = str_replace( '{' . $tag . '}', $templateContent, $this-page-getContent() ); $this-page-setContent( $newContent ); } } Data that we wish to have placed into our templates works in a similar way to template bits, except that we can simply replace the tag with the data passed, as opposed to the contents of another file. There are two exceptions, which require a little more work from us, both of which involve iterating through data. If we have a list of friends of a. | Planning and Developing the Core Framework foreach bits as tag template templateContent file_get_contents template newContent str_replace . tag . templateContent this- page- getContent this- page- setContent newContent Data that we wish to have placed into our templates works in a similar way to template bits except that we can simply replace the tag with the data passed as opposed to the contents of another file. There are two exceptions which require a little more work from us both of which involve iterating through data. If we have a list of friends of a user for instance which we have found via a database query we would want to loop through and place these in the page. Similarly if we were to build our own array of custom data we may wish to iterate through these and place them on the page. To facilitate this the replaceTags method also accepts data as an array if it is an array the first item of the array indicates the type of data Query or Array and the second array points to a cache reference which indicates where it is stored in the database object. Control is then passed to a suitable method to perform more advanced replacements. The pp parameter indicates whether we are processing Post Parse Tags these are tags that only appear after we have performed our first set of tag replacements for example tags defined within database content that is placed into the template . We may wish to insert data into this so we can perform the replaceTags function a second time instructing it to use the array of Post Parse tags as opposed to standard tags. To review Our templates use template tags such as heading to indicate where dynamically generated data should be inserted. Sometimes these template tags are placeholders for other files. Templates are parsed by the replaceTags method. Templates are inserted into template tags via the replaceBits method. If the replacement for a template tag contains another tag for example if we have data in the database for a CMS style .