I want to separate the presentation from the business logic, and i wrote a class.
Template engine working like any other.
Example:
page.tpl
<html><body> <div id="content"> {{content}} </div> </body></html>
index.php
$content_i_want_to_add = 'yeah, this is my page content'; $content->set('content', $content_i_want_to_add);
This part is working great. Problem is when i need to include file on index.php with some data that can be turned on or off. Example:
index.php
$content->set('content', $content_i_want_to_add); if ($show_time == "on") { include"time.php"; } // how to "set" this?
time.php
if ($show_time == "on") { echo '<div align="center">' . date("d.m.Y.") . '<br />' . date("H:i") . '</div>'; }
This is just example, i have a lot of other, more complex, situations when i need to include a file (echo data that i include).
How to solve this?
Did i must to put all data in variable or there is more "elegant" way?
time.php
if ($show_time == "on") { $time = '<div align="center">' . date("d.m.Y.") . '<br />' . date("H:i") . '</div>'; }