10 Replies - 2677 Views - Last Post: 08 June 2008 - 02:57 PM Rate Topic: -----

#1 rjolitz   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 111
  • Joined: 17-May 08

Smarty Template Engine

Post icon  Posted 02 June 2008 - 06:05 AM

Good Morning All.

I've been looking at the Smarty template engine and to be honest, I'm not sure what the advantage here is. More then likely I'm just having one of my more dense moments but could someone who has or is using it, comment on what advantage there is to using it?

Thanks!

Rich
Is This A Good Question/Topic? 0
  • +

Replies To: Smarty Template Engine

#2 MitkOK   User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: Smarty Template Engine

Posted 02 June 2008 - 07:12 AM

If you know the meaning of template engine you'll know the advantages of using Smarty.

http://www.smarty.net/whyuse.php -> Why Use Smarty

http://www.smarty.net/rightforme.php -> Is Smarty right for me?
Was This Post Helpful? 0
  • +
  • -

#3 rjolitz   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 111
  • Joined: 17-May 08

Re: Smarty Template Engine

Posted 02 June 2008 - 07:14 AM

View PostMitkOK, on 2 Jun, 2008 - 07:12 AM, said:

If you know the meaning of template engine you'll know the advantages of using Smarty.

http://www.smarty.net/whyuse.php -> Why Use Smarty

http://www.smarty.net/rightforme.php -> Is Smarty right for me?


I've read all that already but thanks!

What I am looking for is feedback from people who have already used it, pro or con, instead of the reasons from the folks that made it. They, of course, are going to be a bit biased :)

Thanks!!

Rich
Was This Post Helpful? 0
  • +
  • -

#4 mocker   User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Smarty Template Engine

Posted 02 June 2008 - 10:03 AM

It is an easy and clean way to separate your presentation from your logic. I've only used it for one project, but it made it much easier for figuring out how to display the data I needed.

Recently I've been doing mostly perl, during which I use the Template Toolkit, which is pretty much similar. It has saved me a ton of time, not to mention forced me to organize my code better. I think you should definitely have some sort of templating system going for anything bigger than a one-time script.
Was This Post Helpful? 0
  • +
  • -

#5 girasquid   User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Smarty Template Engine

Posted 02 June 2008 - 11:00 AM

I agree with mocker here - that separation is a great tool, especially if your design might be changing over the course of development - or even after the project is completed. Being able to separate the two so that the templates handle all of the presentation and the code handles all of the behavior is crazy useful.
Was This Post Helpful? 0
  • +
  • -

#6 joeyadms   User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Smarty Template Engine

Posted 02 June 2008 - 12:51 PM

Personally, I think smarty will be more effective if used in a team environment when you have designers that know how to use it. It allows them to make design based logic without having to know your particular language.

This also prevents them from designing in and around your programming logic.

Smarty looks awesome, but honestly, when doing a project yourself, you can cleanly use programming logic inside presentation without being messy.

Also a lot of frameworks come with html helpers, that allow you to create presentation data in an object oriented fashion.

Unless there is a good reason too, there is no need to use a template engine on top of a template engine.

Plus it is a language in itself, and do you really want to learn a new one, and you actually use logic with smarty its not just about putting brackets around a variable name.
Was This Post Helpful? 1
  • +
  • -

#7 mocker   User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Smarty Template Engine

Posted 02 June 2008 - 02:30 PM

You can use logic inside a smarty template.. it doesn't mean you have to. And there is a big difference between presentation logic and and programming logic.
Want to know the difference?

You have a bunch of geographical statistics in your databases, maybe some information about countries.. some statistics about cities etc..

Your program is responsible for connecting to the database, pulling the information you want from there, putting it in the proper data structure and then feeding it to the the template

The template decides which presentation file you want to use, and then from the code in there, figures out how to display it. This can include simple loops to generate lists and go through each element.. even though that is 'logic'.

If you want to change how a page looks, you don't have to hunt through the main application, you just change the template file. Want pages to display different subsets of the data? .. Just create multiple template files and point to the proper one.. no need to mess with the data processing. Same thing with skins.


And saying smarty or other template engines is learning another language? That's like saying bbcode is learning a programming language. You need to know html (which you'd need anyways), and a small handful of tags, which generally make sense. If you DO have a designer that would be expected to create the template files, it shouldn't take them any time at all to modify a layout for smarty

If you are using a framework though, you are right in that it doesn't make sense to use templates on top of a template. Most frameworks already seperate presentation from the data and provide tools for that (ie.. any mvc system), so smarty would be pointless in that situation

This post has been edited by mocker: 02 June 2008 - 02:33 PM

Was This Post Helpful? 1
  • +
  • -

#8 joeyadms   User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Smarty Template Engine

Posted 02 June 2008 - 04:52 PM

^ That's what I meant is in an MVC application.

The main point is splitting up logic from business data. In MVC, your Models hold business data, your controllers use programming logic which is then fed to the View which uses presentation logic.

If you are not using an MVC architecture, then yes, using a template engine should be your best priority for maintaining reusable code.

And Smarty has some pretty advanced features, it's more than just putting a variable on a page, or more than loops, they do conditionals and all sorts of things.

What I meant was, assuming you are using MVC architecture, there is no reason, unless you know smarty, or are in a team based environment where a designer would have problem searching through your logic, to use a template engine like smarty.
Was This Post Helpful? 0
  • +
  • -

#9 Mike007   User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 332
  • Joined: 30-August 07

Re: Smarty Template Engine

Posted 02 June 2008 - 08:21 PM

Well for once, smarty and template engines encourage you to think about your design separately from your code. And it will not usually let you get away with quick dirty code that will be a hell to modify later when you change the design, or would try to change it. Smarty also has this very cool feature called "smarty plug-ins" where you can create your own plug-in and put it anywhere in your template. This helps you create reusable code that can be used in any of your future projects. An example would be a weather plug-in, displaying the current weather pulled from some database or maybe scraped from some news page.

So if you balance the use of ajax and smarty plug-ins together with their templates, you can get some pretty nice code going for you. (Obviously it's not as easy as it sounds but with some practice this should work great).

Cons, umm, i would say that you might lose the sense of feeling what is going to be printed before what to HTML, which can be a problem sometimes like when you want to write cookies or send headers, or simply when you use picture in a template that is included in another template. But all of this can be solved with some good planning.
Was This Post Helpful? 0
  • +
  • -

#10 silverblaze   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 69
  • Joined: 18-January 08

Re: Smarty Template Engine

Posted 02 June 2008 - 08:57 PM

well if u ask me i am working with smarty from the time i start coding with php. Infact i havnt actually done a project without using a template engine. The reason is that i dont like my code to be bulky by adding HTML and CSS tags also. More over if u use smarty or any kind of template engine it will give u a huge advantage during the debugging sessions. Also its much more simpler to change designs and templates. I used to change designs, modify or add, designs often, in such cases smarty comes in very handy.

Also like joeyadms said when working in a team environment smarty is somethin you can relay on. Because in such cases it is not nessary that the coder is fully comfortable with the design( like myself) and also the designer is comfortable with the coding language. So smarty will help you a lot.

Even though smarty is another language it is not so tough to learn. You can get the basics in just a single day which is enf to use most of the functions of smarty.

hope this will help you.

Take care. :)
Was This Post Helpful? 0
  • +
  • -

#11 rjolitz   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 111
  • Joined: 17-May 08

Re: Smarty Template Engine

Posted 08 June 2008 - 02:57 PM

Thanks for all the input folks!

I've been playing with it and actually rather like the way it works. The seperation is easier to make adjustments from what I can see.

The proof will be in the pudding as I now move on to using it to convert a forms based / manually updated website to one using SMARTY and DB driven.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1