It is good that you are trying to separate concerns, you feel and probably have heard that templating is some form of best practice, but the how and why is somewhat vague to you. I know what it feels like.
Templates are a means to separate "business logic" from the view. Business logic is something like update a record in the database, checking rights etc.
There is one rule: the view may access data, but not change it!
So: is accessing data from an object right? Yes, it is!
There is a design pattern that is the defacto standard for good web application design: Model View Controller (MVC)
The Model contains all data and rules about your domain (for instance: bicycles, customers, cats, processes).
The View asks for data and displays it somehow. Nor the model nor the controller should dictate how information is presented. It is up to the View.
The Controller should be thin: given an request (bicycles.com/product/345) it instantiates the appropriate view (template) and tells it to render.
If an invalid request is made, the controller should do a redirect to an error page, log it or what else. The controller is a delegating object.
On the internet many examples are shown of a controller class
- that gets a certain database identifier from a request
- pulls the data out of the database
- instantiate a template with only variables like you've shown
- and say: template->render();
Well that's a nice controller, except the 3rd item. One should strive for thin controllers. The View should get the data it wants.
In you controller you have:
// file: ProductController.php
$view = new TemplatingSystem();
$view->productId = $_GET['product-id'];
So in your template you ideally have
// file: products.tpl
// $this is the template object. In smarty it is $smarty
$bicycle = Bicycles::getById($this->productId)
echo 'model: ', $bicycle->model;
I recommend reading http://blog.astrumfutura.com/archives/353-An-Example-Zend-Framework-Blog-Application-Part-2-The-MVC-Application-Architecture.html since it will teach you a lot about MVC.
I've used smarty in the past, and it has been a very bad choice. You'd better of with Savant or Zend_View from Zend framework [Zend View is a modification of Savant].
- Writing your own MVC-framework is hard. I recommend picking an existing one.
- Smarty is a bad choice: working with real php objects is only easy in real php, not some cumbersome limiting syntax.
- Zend Framework supports Smarty too, if refactoring is a too big burden.