SitePoint Sponsor |
|
User Tag List
Results 76 to 100 of 100
Thread: Smarty 2.2.0 Released
-
Feb 18, 2003, 19:08 #76
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
well i'll be honest, I've never really used smarty, it just seemed too generalized for any real project I've had to work on.
My templates are also only parsed once, and never again unless you change them.Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
Feb 18, 2003, 20:40 #77
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by wogboy
It might make the initial compilation of the template slower as the regexp needs to be more complicated to support it, but from there on you are just executing native PHP until the template changes again.i've discovered that my scripts run so fast that my biggest enemy (slowdown) is the compilation time. this is why the PHP accelerators help tremendously.
on my 800MHz Win2k system, i've discovered that it takes PHP about 1ms to compile only 2KB of code! i think that's pretty slow. this includes any bytes in the file -- newlines, spaces, etc. even a comment takes as much time to parse as regular code. so, yes, that means having comments in your code slows it down (not the run-time, though, so it's eliminated if you have an accelerator).
man, i wish every host had an accelerator or the functionality was included in PHP.- Matt** Ignore old signature for now... **
Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
"Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR
-
Feb 18, 2003, 20:46 #78
- Join Date
- Jun 2002
- Location
- Melbourne
- Posts
- 56
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sure, PHP Accelerator and compiled smarty templates work really well together since the compiled template is just regular PHP code.
I don't think a bytecode cache will appear in PHP as long as Zend is able to sell one!
-
Feb 18, 2003, 20:54 #79
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by wogboy
I don't think a bytecode cache will appear in PHP as long as Zend is able to sell one!greedy Zend wants to rip people off instead of trying to make PHP better. from what i've heard from Nick on the PHP Accelerator forums, it sounds like Zend is using some nasty practices to try and make his, and other competitors', products look bad.
at least for now we have the free PHPA and Turck MMCache available. let's hope Zend doesn't modify PHP as to not allow use of these products.
i just wish it was built-in because the repeated compiling hurts PHP's performance so much.Last edited by DR_LaRRY_PEpPeR; Feb 18, 2003 at 20:56.
-
Feb 18, 2003, 21:12 #80
- Join Date
- Jun 2002
- Location
- Melbourne
- Posts
- 56
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, Nick's comments mostly related to the Encoder's they both produce.
As long as PHP is open source, I don't think there is much worry about people not being able to produce the accelerators, encoders and whatever else.
-
Feb 18, 2003, 22:50 #81
Question
Say I for the body part i have a huge body. Where i echo tables, varibles perform all kinds of opperations. Am i supposed to shove all this content into a $body varible then just include the template. Seems like sloppy code to me.
-
Feb 18, 2003, 23:03 #82
- Join Date
- Dec 2001
- Location
- Sioux City, Iowa
- Posts
- 691
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I would rather just teach the designer to use PHP arrays, if/else structures, and while loops then make some template engine with weird syntax and teach that to them instead. There is no reason for a template engine.
-
Feb 20, 2003, 05:19 #83
- Join Date
- Jan 2003
- Location
- Estonia / Tallinn
- Posts
- 201
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here comes my one cent
...up until now I was not 100% sure if PHP was really usable in template files, but recently tried it and frankly - it seems to work just fine for me.
And just for clarity, here is a little example of a template that uses PHP as it's engine.
PHP Code:// values for: $totalPages, $prevPage, $nextPage and $pages
// are set in another file -> in a business logic layer.
<?if($totalPages > 1):?>
<TR>
<TD colspan="2">
<?if($prevPage):?>
<A href="<?=$prevPage?>">Prev</A>
<?endif;?>
<?foreach($pages as $nr => $href):?>
<?if($nr == $currentPage):?>
[<?=$nr?>]
<?else:?>
<A href="<?=$href?>"><?=$nr?></A>
<?endif;?>
<?endforeach;?>
<?if($nextPage):?>
<A href="<?=$nextPage?>">Next</A>
<?endif;?>
</TD>
</TR>
<?endif;?>
I have to say that I feel damn good if there is not a single echo in my business layerTemplates are good things. Like you did'nt know that before
I'll skip Smarty and other XXX engines for a wild.
just an opinion,
- MarekS -Last edited by MarekS; Feb 20, 2003 at 05:22.
-
Feb 20, 2003, 05:43 #84
- Join Date
- Sep 2001
- Location
- Singapore
- Posts
- 5,269
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by cyborg from dh
after rethinking some things... it appears my point on smarty having too many features is strengthened.
Why support the other syntax? It just makes it slower.
If features are useful enough, they should be included, unless there is a premise to keep the product lightweight. Besides, Smarty's features are not overly many - the only problem I see is with the complicated syntax (esp. for looping constructs).
Ask yourself: Why should PHP have so many features? Why try to make it an OOP? What we want is god-damn speed isn't it?
Regarding supporting other syntax, there seems to be something you don't realise (for someone who seems to want speed) - PHP isn't machine syntax. To your machine, it is 'other' syntax. PHP gets compiled to bytecode/executables. PHP adds a layer of complexity above the C language used under the hood. C itself hides and protects users from writing in assembly. Assembly keeps us away from having to enter 1's and 0's.
All these make your PHP script run slower, because you're speaking another language to your machine. Why do you use PHP?
-
Feb 21, 2003, 08:38 #85Originally posted by redemption
PHP adds a layer of complexity above the C language used under the hood. C itself hides and protects users from writing in assembly. Assembly keeps us away from having to enter 1's and 0's
SeanHarry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature
-
Mar 14, 2003, 04:40 #86
- Join Date
- Mar 2001
- Location
- Tampa, FL
- Posts
- 376
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I would actually rather see a JSTL implementation instead of ASP.NET
JSTL allowed you to use a core set of XML namespaces (or ones you created and built handler code behind them) to manipulate the output. JTL's, if ported to PHP correctly, would be the next best thing for PHP.
-
Jul 9, 2004, 06:30 #87
- Join Date
- Jul 2004
- Location
- france
- Posts
- 1
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi, I just want to give some answers to "why a template engine can be usefull", based on my experience. I'm pretty sure I won't change your mind, but let's try.
Originally Posted by voostind
They do not add any features to PHP not already there
To give some examples, let's say "mailto" (with email simple encryption), date_select, time_select, popup, html_table, truncate, strip and so on (and you can write your owns).
Of course, you can always do the same in PHP, but Smarty provide a "ready and easy to use" way.
Let's take an example, like truncate.
in Smarty, you do this:
{$myText|truncate:30}
If your text is over 30 characters, you will get
"my text my text ..."
In PHP, you would do:
<?php echo strlen ($myText) > 30 ? substr ($myText, 0, 27) . '...' : $myText; ?>
It's not that big, but let's face it, it IS easier with Smarty.
What does a template engine enable us to do? It allows us to separate content from business logic by supplying it with a template file.
A lot of you will probably say: "Yeah, right! This may work for simple examples as these, but for more complicated web sites, template engines are a real asset!"
That is not true.
Because PHP already is a template engine. Examine all template engines you can think of, and compare their features with those of PHP. PHP has them all. And more.
In smarty
<select name=customer_id>
{html_options values=$cust_ids selected=$customer_id output=$cust_names}
</select>
IN PHP
<select name=customer_id>
<?php
foreach ($cust_ids as $value=>$caption){
echo '<option value='.htmlentities ($value).' '.($value == $selected ? 'selected="selected" : ' '').'>'.htmlentities ($caption).'</option>';
}
?>
</select>
So why do people think we need a template engine?
At this point I also like to point out that saying "The layout must be strictly separated from the content" is a moot point. What is the layout? That's the colors, the fonts, the styles and so on. The plain HTML itself is the content.
CSS enables you to change the way things are displayed, not the structure.
You cannot, using CSS, choose wether you'll display elements a list (ul li) or in a table.
Another answer to the question "Why do people think we need a separate template engine?" is the following: the biggest part of the PHP community (and the ASP community, for that matter) knows nothing about software architecture.
I have been programming now for
Q: If you use variables like '$title', as in your example, all over your code, then the business logic becomes a mess, and there is a possibility of clashes between such variables.
A: Then don't use these (global) variables. With little effort you can set up a simple class (or other structure) that stores the values for the page you are creating, allowing you to nicely separate presentation code from the business code.
Q: The 'better' template engines have a cache to make loading of pages much faster. Clean PHP doesn't do this, so the template engine is, in that case, faster!
A: Incorrect. The cache in a template engine is needed to store the parsed template in some other format (Smarty uses PHP for that), which can then be instantly restored. With clean PHP the format is already correct, so there is no need to use a cache. Less and simpler lines code, faster execution.
The PHP compilation is here to avoid multiple parsing, it is not the cache we're talking about in this question.
Let's agree that all Smarty can do PHP can, but that Smarty is a good way of doing so.
[EDIT: LOL i didn't notice how old the post was..... sorry]
-
Jul 9, 2004, 07:22 #88
- Join Date
- Jan 2003
- Location
- Munich, Germany
- Posts
- 1,391
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by gerald
We are the Borg. Resistance is futile. Prepare to be assimilated.
I'm Pentium of Borg.Division is futile.Prepare to be approximated.
-
Jul 9, 2004, 07:38 #89
- Join Date
- Nov 2001
- Location
- Atlanta, GA, USA
- Posts
- 5,011
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by gerald
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
-
Jul 9, 2004, 08:51 #90
- Join Date
- May 2003
- Location
- virginia
- Posts
- 988
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I totally disagree that Smarty is ready to go out of the package an php is not. Your examples are showing that people that use php, don't use classes or functions. Just raw php. What about a php class that is meant to handle templating?
IN PHP
Code:<select name=customer_id> <?php foreach ($cust_ids as $value=>$caption){ echo '<option value='.htmlentities ($value).' '.($value == $selected ? 'selected="selected" : ' '').'>'.htmlentities ($caption).'</option>'; } ?> </select>
You're assuming that there's no such thing as a pure php class that handles form elements? Why not:
Code:<?php foreach ($this->getCustomerSelectValues() as $element){ ?> <?php echo $element->getOutput(); ?><br/> <?php } ?>
<?php echo $this->get('lastname, 'truncate', 30); ?>
OK, so a little longer than the Smarty example so how about:
<?= $this->get('lastname'); ?>
And let the presentation logic get handled where it should get handled, meaning not in the template?
Sorry, I don't think I can be convinced!
Matt
-
Jul 9, 2004, 09:08 #91
- Join Date
- Nov 2001
- Location
- Atlanta, GA, USA
- Posts
- 5,011
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by mwmitchell
Smarty has taken a number of very common presentation techniques and done them for you, that is its draw. If you find Smarty too limiting or don't care for the learning (memorization) curve don't use it.
I don't know why presentation logic shouldn't be handled in the template, where else can it really go? Business logic, sure, keep that out of presentation. But presentation logic? That sounds like something that would be good to task a graphic designer with handling, assuming you could make it simple enough. Again, this is what makes Smarty a potential solution. Not "the" solution, but certainly a possibility.Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
-
Jul 9, 2004, 10:00 #92
- Join Date
- May 2003
- Location
- virginia
- Posts
- 988
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by samsm
Originally Posted by samsm
The only value I see in 'templating' engines other than php is to restrict access in templates from un-template related functionality. That's it. I guess you could say the syntax looks better, but I don't think so and I don't care anyway.
I'm not saying which is better, these are only my opiniona!
Matt
-
Jul 9, 2004, 10:07 #93
- Join Date
- Jan 2003
- Location
- Munich, Germany
- Posts
- 1,391
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by samsm
Without argueing about how good Smarty is/may be (i don't know, i don't use it), if you want something 'out of the box'
Smarty (or others) might be something to think about.
Depending on the requirements i'm writing my functions and classes and are more than happy with it.
i now have a pretty good collection of usefull stuff (which always can and will be improved and extended),
and for me the advantage is, that i know how to handle and to use those functions and classes, since it's my own and not 3rd party.We are the Borg. Resistance is futile. Prepare to be assimilated.
I'm Pentium of Borg.Division is futile.Prepare to be approximated.
-
Jul 9, 2004, 11:07 #94
- Join Date
- May 2003
- Location
- virginia
- Posts
- 988
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey, http://phpsavant.com/ is one way it can be done. This is just an example - I don't use it myself.
Matt
-
Jul 9, 2004, 11:48 #95
- Join Date
- Nov 2001
- Location
- Atlanta, GA, USA
- Posts
- 5,011
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The other advantage for templating languages is that you don't have to hand the power of PHP over to a someone untrained who will in turn do something silly. They are limited to the range of silliness that the templating language allows. :-)
Also, the hope is that the templating language will be more logical to a designer (who has no or little invested programming knowledge) and/or will work more strongly in WYSIWYG editors. I don't know if any templating language delivers on that, but it is certainly a potential advantage.Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
-
Jul 9, 2004, 16:19 #96
- Join Date
- Jan 2003
- Location
- Munich, Germany
- Posts
- 1,391
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by mwmitchell
We are the Borg. Resistance is futile. Prepare to be assimilated.
I'm Pentium of Borg.Division is futile.Prepare to be approximated.
-
Jul 9, 2004, 23:47 #97
- Join Date
- Jan 2004
- Location
- Kentucky, USA
- Posts
- 1,099
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've always thought third-party templating engines were a waste of time. I see nothing wrong with something like like this...
Code:<?php class globaltemplate { function webpageheader($parameter) { return <<<EOF WEBPAGE HEADER CODE GOES HERE [ $parameter ]... EOF; } function webpagefooter($parameter) { return <<<EOF WEBPAGE FOOTER - COPYRIGHT $parameter EOF; } } ?>
Code:<?php require('./globaltemplate.php'); $globaltemplate = new globaltemplate; $output = $globaltemplate->webpageheader(); $output .= "CONTENT GRABBED FROM DATABASE, FOR EXAMPLE"; $output = $globaltemplate->webpagefooter(); echo($output); ?>
It's pretty simple for others to dive in and modify the look of the pages while remaining fast by not having to use any extra template parsers or anything like that, PHP itself is a template parser, use it. This above example has another benefit, if you encounter an error within your script (such as database connection failing) you can erase everything in $ouput and then grab your error template and put that as $output so nothing is displayed on the page except for the error. It's easily extensible as well.
Invision Power Board uses this method of templating, so that is proof that the system works and they are not at the mercy of other developers which is always a good thing.
-
Mar 24, 2005, 13:23 #98
- Join Date
- Nov 2002
- Location
- Romania
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
For those who still are interested in Fast Template
Fast Template is again developed and now from 1 year was added a lot of new functionalities to it.
Check it at http://www.grafxsoftware.com/product...t_Template/26/
Hope this help a few programmers
-
Jun 10, 2005, 05:07 #99
- Join Date
- Jun 2005
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I know this thread is old, but there is still a ton of useful information here.
as a novice (I say novice cause I know how far I need to go to call myself and expert) level coder I started from the perspective many of you are arguing in behalf of... the designer. I started as a designer working with a few different template systems. I didn't know PHP from HPH, for a few projects I had to learn this or that template language and there 'simplified' tag systems.
I learned them used them effectivly etc. As I progressed though I started digging into and looking at the code of the template engine's and scratching my head as the the php started to make logical sense to me.
I spent many long long hours learning template systems, time knowledge and brain power wasted. If back in the begining I had started learning PHP (or ASP etc) to do this I would be so much farther along in my knowledge.
As so many have said before me template systems have there uses, php IS a template system (and growing into a OOP language but still very young) why write/work with a parser thats parsed by a parser then output. Template engines parse tags and convert them to php that is then parsed.
from the smarty website:
Template take time to parse, making applications much slower.
That may be true in some cases, but with Smarty it is no slower than executing a PHP script. On the first execution of a template, Smarty converts the template files into PHP scripts..."
twice the work for the same results... the coder may not be doing twice the work but the server is, its compiling the same code twice.
So in using a template system, first someone has to learn this quarky language, and the server has to do twice the job. Why not enable the designer with more skill and save a few cpu cycles.....
-
Jun 10, 2005, 06:30 #100
- Join Date
- May 2001
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This point has been beaten to death, but I'll reply...
You are taking this purely from a technical standpoint. Of course it would be quicker to write a web page directly in PHP instead of the extra step Smarty takes to compile (which happens only once btw) before displaying the template.
But what you are gaining is the utility of the template engine. Smarty isn't just a tag-replacement templating system, it is full-featured presentation framework for your application, automating and simplifying many tasks that would otherwise have to be programmed (and debugged) manually. Look through the testimonial section of the forum, you will see examples where Smarty has reduced time-to-production by magnitudes.
Of course Smarty isn't ideal for every situation. Maybe another engine, or roll your own works for you. Smarty is just a tool for the PHP developer toolbox. It has saved me and many others countless hours of development and maintenance costs.
Bookmarks