TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Template Engine (http://www.talkphp.com/general/4001-template-engine.html)

hello-world 02-25-2009 11:12 PM

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 `?

allworknoplay 02-26-2009 12:29 AM

Quote:

Originally Posted by hello-world (Post 21939)
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...

Enfernikus 02-26-2009 01:35 AM

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

Wildhoney 02-26-2009 01:39 AM

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.

allworknoplay 02-26-2009 02:06 AM

Quote:

Originally Posted by Enfernikus (Post 21945)
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 02-26-2009 02:13 AM

Quote:

Originally Posted by Wildhoney (Post 21946)
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. :-P

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

$row[color] ? "#e0e0e0" : "#EEEEEE";

hello-world 02-26-2009 01:17 PM

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 ?

Tanax 02-26-2009 02:16 PM

I wouldn't use smarty, nor learn it.

Orc 02-27-2009 07:52 PM

Tried it, didn't like it, thus I went ahead and made my own which takes on a hybrid of PHP and XML.

triumvirat 03-17-2009 08:39 AM

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.

delayedinsanity 03-17-2009 08:55 AM

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.

allworknoplay 03-17-2009 03:56 PM

Quote:

Originally Posted by triumvirat (Post 22285)
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 (Post 22288)
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...

ETbyrne 03-17-2009 05:04 PM

Yep, I use PHP as my template engine too.

PHP Code:

<h2><?=$title;?></h2>

Simply love it!

hello-world 03-17-2009 10:43 PM

Quote:

Originally Posted by triumvirat (Post 22285)
Smarty - the PHP writеten in PHP. IMHO.

It is written in C++.
Well for it smarty makes code readable for designers.

delayedinsanity 03-18-2009 03:03 AM

Quote:

Originally Posted by hello-world (Post 22313)
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! ;)

Village Idiot 03-18-2009 05:19 AM

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.

delayedinsanity 03-18-2009 05:43 AM

Quote:

alternating colored tables
Why use PHP to do this at all? CSS can handle that just fine.

triumvirat 03-18-2009 07:19 AM

Quote:

Originally Posted by hello-world (Post 22313)
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; ?>


allworknoplay 03-18-2009 01:19 PM

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....

hello-world 03-18-2009 01:31 PM

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 (Post 22337)

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.


All times are GMT. The time now is 11:55 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0