Writing a Template System in PHP - Including Dynamic Files
(Page 7 of 9 )
At this point the class is sufficient to template plain text and HTML files, but a greater level of functionality might be desired. For example, what if the user wanted to insert a footer section that contains dynamic data such as the date or page address? It would definitely be nice if the templating script would make allowances for other script files.
I modified replace_tags to pass data that validates as a file name off to a private function.
Parse accepts the name of a file and includes its contents (include will processes any PHP directives found within the file). Output buffering is used to store the processed data so we can return it and prevents the included file from being sent to standard output prematurely.