SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 28
-
May 6, 2009, 01:07 #1
- Join Date
- Nov 2005
- Location
- Molde, Norway
- Posts
- 31
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What't the point of a template engine in a framework
I have been developing some functionality to PHP applications, but I haven't myself been making design or too much logic in the applications. Just algorithms and data structures, so I haven't been needing to understand how the application works.
Now I have looked into frameworks and application structure, and I start wondering what the point of template engines are when working with a framework? For example, I am looking into Yii and Zend framework and the use of Smarty templates. Most of the HTML output is generated by PHP code, and in the end all this HTML is inserted into an almost empty HTML file.
Many of my templates are just empty shells where I insert a Zend Form. I don't see the need for templates. Is there something I have missed, can someone put me in the right direction?
-
May 6, 2009, 05:00 #2
- Join Date
- Dec 2003
- Location
- norway
- Posts
- 61
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Reading about the reasons why to use Smarty templates on their own website, they talk some about that designers and programmers can work separated. The designers work on the templates and the programmars on application code.
So if that is a problem then it maybe could be a good approach to use something like Smarty..
"One of Smartys primary design goals is to facilitate the separation of application code from presentation. "
I try to separate application logic from presentation logic
having php loops in a the presentation layer for example has never caused a problem for me..
-
May 6, 2009, 05:17 #3
- Join Date
- Sep 2006
- Location
- Nottingham, UK
- Posts
- 3,133
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Personally I think Smarty is horribly over complicated, and you don't really need a templating engine with a framework, as php is its own templating engine. However, there are some engines I quite like (xtpl being one), that really do separate presentation and logic (smarty still has if, foreach loops) and make maintenance easier as well. I've written my own templating engine based on the xtpl syntax. It uses blocks instead of loops - a block of code can be repeated 0 or more times - so that's conditions and loops taken care of without having to put those in the template.
-
May 6, 2009, 05:21 #4
- Join Date
- Nov 2005
- Location
- Molde, Norway
- Posts
- 31
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is just a template example out of many similar from a project I am working on:
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Here goes the title</title> </head> <body> <h1>Activation</h1> {$form} </body> </html>
I use Zend forms. Isn't the purpose of a template in this example gone?
-
May 6, 2009, 05:23 #5
-
May 6, 2009, 05:58 #6
- Join Date
- Nov 2005
- Location
- Germany
- Posts
- 235
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 6, 2009, 06:59 #7
- Join Date
- Nov 2005
- Location
- Molde, Norway
- Posts
- 31
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 6, 2009, 08:09 #8
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The best reason to use Smarty is to keep designers out of your code. If you're the sole developer on a project (both front end and back end) there's no real reason not to just use PHP inline syntax.
-
May 6, 2009, 08:28 #9
- Join Date
- Sep 2006
- Location
- Nottingham, UK
- Posts
- 3,133
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
The trouble is, Smarty easily has the potential to break your code anyway. It has conditions, loops, array parsing, all sorts - easily enough for a designer to screw around with and mess things up. This is why I think smarty is over complicated as well. A look at the size of the documentation on the smarty site should tell you that is has too much power for a template engine (and therefore too much bloat).
-
May 6, 2009, 08:44 #10
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've about decided that server-side template systems are passe in this age of AJAX and JST anyway. Let the client handle rendering the view. That's what browsers are made for.
-
May 6, 2009, 08:45 #11
-
May 6, 2009, 08:51 #12
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's impossible for a client-side JavaScript template system to break your PHP code unless you specifically give it that ability via AJAX calls or some other means.
-
May 6, 2009, 09:14 #13
-
May 6, 2009, 09:30 #14
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 6, 2009, 10:32 #15
- Join Date
- Oct 2005
- Posts
- 51
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 6, 2009, 11:13 #16
-
May 6, 2009, 11:20 #17
- Join Date
- Oct 2005
- Posts
- 51
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
With power i do mean expressiveness. It should be possible to perform a simple string reverse or split by means of little syntax. Php is perfect for that.
Not all display logic should go into yet another view helper. But I agree that when reading your template you should easily the what, and not be bothered by the what. Many lines of formatting procedures into a template are not so nice. I think for example that putting breadcrumbs, pagination etc into a view helper is almost always a good idea.
-
May 6, 2009, 11:30 #18
-
May 6, 2009, 12:00 #19
- Join Date
- Oct 2005
- Posts
- 51
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:see your name reversed: <?php echo strrev($name); ?>
PHP Code:see your name reversed: <?php echo $this->reverse($name); ?>
-
May 6, 2009, 12:23 #20
-
May 6, 2009, 12:30 #21
- Join Date
- Oct 2005
- Posts
- 51
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
And where do you want to put
PHP Code:$objTemplate->assign('REVERSED_NAME', strrev($name));
-
May 6, 2009, 12:53 #22
-
May 6, 2009, 12:57 #23
- Join Date
- Nov 2005
- Location
- Germany
- Posts
- 235
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 7, 2009, 02:58 #24
- Join Date
- Oct 2005
- Posts
- 51
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I agree with FrlB. The controller shouldn't know about whether a name needs to be displayed reverse or something.
"business logic in the controller".
That's bad imho. Business logic should be put in the Model. The Model is not just data, it is a model.
Originally Posted by http://blog.astrumfutura.com
-
May 7, 2009, 03:21 #25
Bookmarks