TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-25-2009, 11:12 PM   #1 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default Template Engine

Last week I started working Smarty Engine.I came to know that it is almost a language.It has its own loops,functions and etc.
Do I really need to learn Smarty `?
hello-world is offline  
Reply With Quote
Old 02-26-2009, 12:29 AM   #2 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by hello-world View Post
Last week I started working Smarty Engine.I came to know that it is almost a language.It has its own loops,functions and etc.
Do I really need to learn Smarty `?
I've been reading up on Smarty as well. I'm not sure...

Some people are saying what's the point? especially if you are using a framework...

As frameworks get better with their MVC, template engines like Smarty are going to be obsolete...

I was going to really get into Smarty but decided not to. I have enough things on my plate. I am going to concentrate on PHP and the Zend Framework...
allworknoplay is offline  
Reply With Quote
Old 02-26-2009, 01:35 AM   #3 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

In simple terms, if your project is going to include many a designer who is not apt at basic PHP then it's best to use a templating engine unless you plan to do all the front end xhtml/css work as well
Enfernikus is offline  
Reply With Quote
Old 02-26-2009, 02:06 AM   #4 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Enfernikus View Post
In simple terms, if your project is going to include many a designer who is not apt at basic PHP then it's best to use a templating engine unless you plan to do all the front end xhtml/css work as well
Right....that is a good point.

Unfortunately for me I wear many "hats"...
allworknoplay is offline  
Reply With Quote
Old 02-26-2009, 01:39 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

The gripe I have with Smarty and other such template engines is precisely what has been mentioned! Why should we learn another seemingly differently language? Why are they creating yet another language for us to use when we have so many already at our disposal?

In my personal opinion, PHP is most certainly more than capable of handling this type of thing. However, I use the other syntax for the conditionals. Which is the following:

Code:
<?php if ($myVariable): ?>
<b>My variable has been set!</b>
<?php endif; ?>
For certain things, such as alternate row colours, I have created myself a class called a Zebra class. I am not sure where I got that name from, it must be my over-active imagination once again! And simply call it like below. You are even able to specify conditionals for a different row colour.

html4strict Code:
<div class="<?php echo TalkPHP_Zebra::getNext(); ?>">TalkPHP loves you.</div>

I don't see why people choose to use Smarty? Perhaps somebody could explain this to me.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-26-2009, 02:13 AM   #6 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
The gripe I have with Smarty and other such template engines is precisely what has been mentioned! Why should we learn another seemingly differently language? Why are they creating yet another language for us to use when we have so many already at our disposal?

In my personal opinion, PHP is most certainly more than capable of handling this type of thing. However, I use the other syntax for the conditionals. Which is the following:

Code:
<?php if ($myVariable): ?>
<b>My variable has been set!</b>
<?php endif; ?>
For certain things, such as alternate row colours, I have created myself a class called a Zebra class. I am not sure where I got that name from, it must be my over-active imagination once again! And simply call it like below. You are even able to specify conditionals for a different row colour.

html4strict Code:
<div class="<?php echo TalkPHP_Zebra::getNext(); ?>">TalkPHP loves you.</div>

I don't see why people choose to use Smarty? Perhaps somebody could explain this to me.

Yeah like I said, I have enough on my plate...so I would have to learn another language to work with PHP, a language of itself?

that's like speaking to an interpreter only for him/her to interpret yet again!!

Zebra!! I love that name!!! I think I am going to steal it.

This is what I use for changing TR colors...

$row[color] ? "#e0e0e0" : "#EEEEEE";
allworknoplay is offline  
Reply With Quote
Old 02-26-2009, 01:17 PM   #7 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

Thanks for taking your time and replying me.
There wouldn't be any designer for my project.But I want a project with more than one Template.Do I still no need Smarty ?
hello-world is offline  
Reply With Quote
Old 02-26-2009, 02:16 PM   #8 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I wouldn't use smarty, nor learn it.
__________________
Tanax is offline  
Reply With Quote
Old 02-27-2009, 07:52 PM   #9 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Tried it, didn't like it, thus I went ahead and made my own which takes on a hybrid of PHP and XML.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 03-17-2009, 08:39 AM   #10 (permalink)
The Wanderer
 
triumvirat's Avatar
 
Join Date: Dec 2008
Location: Russia, Moscow
Posts: 14
Thanks: 0
triumvirat is on a distinguished road
Default

Use strict PHP as template engine:

PHP Code:
                <? foreach($user_data as $row):?>
                <tr class="center color_hover">
                    <td><?=$row["id"]?></td>
                    <td><a href="?id=<?=$row["id"]?>"><?=$row["user_name"]?></a></td>
                    
                    <td><a href="/admin/user/?id_country=<?=$row['user_country']?>"><?=$row['country_name']?></a>, <a href="/admin/user/?id_region=<?=$row['user_region']?>"><?=$row['region_name']?></a>, <a href="/admin/user/?id_city=<?=$row['user_city']?>"><?=$row['city_name']?></a></td>
                    
                    <td>
                    <? if($row["user_icq"]): ?>
                        <img src="http://web.icq.com/whitepages/online?icq=<?=$row["user_icq"]?>&amp;img=5" alt="" />
                    <? else: ?>
                        <img src="<?=$http_images_system_icons?>icq_empty.png" alt="" />
                    <? endif; ?>
                    </td>
                    <td>
                    <? if($row["user_url"]): ?>
                        <a onclick="return open_window(this.href)" href="<?=$row["user_url"]?>"><img src="<?=$http_images_system_icons?>homepage_noempty.png" alt="" /></a>
                    <? else: ?>
                        <img src="<?=$http_images_system_icons?>homepage_empty.png" alt="" />
                    <? endif; ?>
                    </td>
...............
Smarty - the PHP writеten in PHP. IMHO.
triumvirat is offline  
Reply With Quote
Old 03-17-2009, 10:43 PM   #11 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

Quote:
Originally Posted by triumvirat View Post
Smarty - the PHP writеten in PHP. IMHO.
It is written in C++.
Well for it smarty makes code readable for designers.
hello-world is offline  
Reply With Quote
Old 03-18-2009, 03:03 AM   #12 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
Originally Posted by hello-world View Post
It is written in C++.
Well for it smarty makes code readable for designers.
Smarty, which I think he was referring to, is written in PHP. So it's an uncompiled child language. Using Smarty won't improve your readability at all if you already write messy PHP code either, so we're still looking for the pro's! ;)
delayedinsanity is offline  
Reply With Quote
Old 03-18-2009, 07:19 AM   #13 (permalink)
The Wanderer
 
triumvirat's Avatar
 
Join Date: Dec 2008
Location: Russia, Moscow
Posts: 14
Thanks: 0
triumvirat is on a distinguished road
Default

Quote:
Originally Posted by hello-world View Post
Well for it smarty makes code readable for designers.
I do not agree.

If the designer is not an idiot, then he will not understand the complexity and the "strict" syntax of PHP.


What is the difference between the following structures for a designer?

Smarty:
PHP Code:
{include file=$includeFile
PHP:
PHP Code:
<? include($includeFile);
Smarty:
PHP Code:
<select name="company">
  {
html_options options=$vals selected=$selected_id}
</
select
PHP:
PHP Code:
<select name="company">
<? foreach($company as $option): ?>
<option value="<?=$option['value']?>"><?=$option['text']?></option> 
<? endforeach; ?>
Smarty:
PHP Code:
{if $name eq 'Fred'}
    
Welcome Sir.
{elseif 
$name eq 'Wilma'}
    
Welcome Ma'am.
{else}
    Welcome, whatever you are.
{/if} 
PHP:
PHP Code:
<? if ($name == 'Fred'): ?>
    Welcome Sir.
<? elseif($name == 'Wilma'): ?>
    Welcome Ma'am.
<? else: ?>
    Welcome, whatever you are.
<? endif; ?>
triumvirat is offline  
Reply With Quote
Old 03-18-2009, 01:19 PM   #14 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

haha, triumvirat,

Good examples. If one were just a pure designer, the syntax would look just the same.

I don't know that many PURE designers. In fact, in my 10 years in this field, I've only met ONE guy that ever said he can design webpages via photoshop but not touch any code.

Good luck getting a job telling someone that you are talented in web design but don't know any code....

I'm sure most employers are looking for someone that can code and work with the team....
allworknoplay is offline  
Reply With Quote
Old 03-18-2009, 01:31 PM   #15 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

triumvirat that was really nice example.I read about smarty in a book that it ease the job for designers.
I have read many tutorials in which the file_get_contents and preg_match_all are used for a custom Template engine. Should I also avoid using custom template engines ?



Quote:
Originally Posted by allworknoplay View Post

I don't know that many PURE designers. In fact, in my 10 years in this field, I've only met ONE guy that ever said he can design webpages via photoshop but not touch any code.

Good luck getting a job telling someone that you are talented in web design but don't know any code....

I'm sure most employers are looking for someone that can code and work with the team....
Photoshop creates lots of wasted CSS which are not needed all.
It is better to design in photoshop and then recode it with css. And CSS is really flexible for it.
hello-world is offline  
Reply With Quote
Old 03-17-2009, 08:55 AM   #16 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
I don't see why people choose to use Smarty? Perhaps somebody could explain this to me.
Might I offer up that it's the same reason people pay $60+ for a t-shirt and $100+ for a pair of jeans that have a stupid label on them? When the material is worth less than a fraction of that? It's popular. I've hardly picked up a PHP book that didn't plug it.

It strikes me as redundant, personally. It's similar to my dislike of most frameworks, why use thirty pounds of product when one pound is what you need? I would say no, you don't need to learn Smarty unless you have an employer that orders you to.
delayedinsanity is offline  
Reply With Quote
Old 03-17-2009, 03:56 PM   #17 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by triumvirat View Post
Use strict PHP as template engine:

PHP Code:
                <? foreach($user_data as $row):?>
                <tr class="center color_hover">
                    <td><?=$row["id"]?></td>
                    <td><a href="?id=<?=$row["id"]?>"><?=$row["user_name"]?></a></td>
                    
                    <td><a href="/admin/user/?id_country=<?=$row['user_country']?>"><?=$row['country_name']?></a>, <a href="/admin/user/?id_region=<?=$row['user_region']?>"><?=$row['region_name']?></a>, <a href="/admin/user/?id_city=<?=$row['user_city']?>"><?=$row['city_name']?></a></td>
                    
                    <td>
                    <? if($row["user_icq"]): ?>
                        <img src="http://web.icq.com/whitepages/online?icq=<?=$row["user_icq"]?>&amp;img=5" alt="" />
                    <? else: ?>
                        <img src="<?=$http_images_system_icons?>icq_empty.png" alt="" />
                    <? endif; ?>
                    </td>
                    <td>
                    <? if($row["user_url"]): ?>
                        <a onclick="return open_window(this.href)" href="<?=$row["user_url"]?>"><img src="<?=$http_images_system_icons?>homepage_noempty.png" alt="" /></a>
                    <? else: ?>
                        <img src="<?=$http_images_system_icons?>homepage_empty.png" alt="" />
                    <? endif; ?>
                    </td>
...............
Smarty - the PHP writеten in PHP. IMHO.

That is an interesting way to use IF ELSE statement, I've never seen it done that way. Glad to see that it can be done in other ways without always using the "BRACKETS"....

Quote:
Originally Posted by delayedinsanity View Post
Might I offer up that it's the same reason people pay $60+ for a t-shirt and $100+ for a pair of jeans that have a stupid label on them? When the material is worth less than a fraction of that? It's popular. I've hardly picked up a PHP book that didn't plug it.

It strikes me as redundant, personally. It's similar to my dislike of most frameworks, why use thirty pounds of product when one pound is what you need? I would say no, you don't need to learn Smarty unless you have an employer that orders you to.
I agree, this seems to be the same thoughts on a lot of people who look into frameworks and templating engines.

I personally will go ahead and try to learn probably Zend Framework because what I am seeing out there are employers looking for individuals with experience in Zend/CakePHP...and Smarty for templating.

I can't learn them all so I figured I'll roll the dice with Zend.....hopefully it pays off...
allworknoplay is offline  
Reply With Quote
Old 03-17-2009, 05:04 PM   #18 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Yep, I use PHP as my template engine too.

PHP Code:
<h2><?=$title;?></h2>
Simply love it!
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 03-18-2009, 05:19 AM   #19 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Smarty provides more than just PHP, it has a number of functions that are useful for alternating colored tables and things of the sort. To do that with a straight PHP template system would require lots of custom work unless you want to put lots of PHP code in your template.
__________________

Village Idiot is offline  
Reply With Quote
Old 03-18-2009, 05:43 AM   #20 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
alternating colored tables
Why use PHP to do this at all? CSS can handle that just fine.
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template Phraser Scottymeuk Advanced PHP Programming 7 01-08-2009 09:07 PM
Pure PHP template class. abiko Advanced PHP Programming 1 04-02-2008 05:45 PM
MySQLs new storage engine Alan @ CIT MySQL & Databases 0 01-29-2008 10:58 PM
Different style template system? Nor General 2 01-15-2008 01:10 PM
Need your feedback Tanax Absolute Beginners 29 10-11-2007 04:50 PM


All times are GMT. The time now is 10:39 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design