 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
02-25-2009, 11:12 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Feb 2009
Posts: 73
Thanks: 30
|
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 `?
|
|
|
|
02-26-2009, 12:29 AM
|
#2 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by hello-world
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...
|
|
|
|
02-26-2009, 01:35 AM
|
#3 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
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
|
|
|
|
02-26-2009, 01:39 AM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
02-26-2009, 02:06 AM
|
#5 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Enfernikus
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"...  
|
|
|
|
02-26-2009, 02:13 AM
|
#6 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Wildhoney
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";
|
|
|
|
02-26-2009, 01:17 PM
|
#7 (permalink)
|
|
The Contributor
Join Date: Feb 2009
Posts: 73
Thanks: 30
|
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 ?
|
|
|
|
02-26-2009, 02:16 PM
|
#8 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
I wouldn't use smarty, nor learn it.
__________________
|
|
|
|
02-27-2009, 07:52 PM
|
#9 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
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
|
|
|
|
03-17-2009, 08:39 AM
|
#10 (permalink)
|
|
The Wanderer
Join Date: Dec 2008
Location: Russia, Moscow
Posts: 14
Thanks: 0
|
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"]?>&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.
|
|
|
|
03-17-2009, 08:55 AM
|
#11 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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.
|
|
|
|
03-17-2009, 03:56 PM
|
#12 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by triumvirat
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"]?>&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
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...
|
|
|
|
03-17-2009, 05:04 PM
|
#13 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Yep, I use PHP as my template engine too.
PHP Code:
<h2><?=$title;?></h2>
Simply love it!
|
|
|
|
03-17-2009, 10:43 PM
|
#14 (permalink)
|
|
The Contributor
Join Date: Feb 2009
Posts: 73
Thanks: 30
|
Quote:
Originally Posted by triumvirat
Smarty - the PHP writеten in PHP. IMHO.
|
It is written in C++.
Well for it smarty makes code readable for designers.
|
|
|
|
03-18-2009, 03:03 AM
|
#15 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Quote:
Originally Posted by hello-world
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! ;)
|
|
|
|
03-18-2009, 05:19 AM
|
#16 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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.
|
|
|
|
03-18-2009, 05:43 AM
|
#17 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Quote:
|
alternating colored tables
|
Why use PHP to do this at all? CSS can handle that just fine.
|
|
|
|
03-18-2009, 07:19 AM
|
#18 (permalink)
|
|
The Wanderer
Join Date: Dec 2008
Location: Russia, Moscow
Posts: 14
Thanks: 0
|
Quote:
Originally Posted by hello-world
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; ?>
|
|
|
|
03-18-2009, 01:19 PM
|
#19 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
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....
|
|
|
|
03-18-2009, 01:31 PM
|
#20 (permalink)
|
|
The Contributor
Join Date: Feb 2009
Posts: 73
Thanks: 30
|
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
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.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|