SitePoint Sponsor

User Tag List

Page 4 of 4 FirstFirst 1234
Results 76 to 100 of 100
  1. #76
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    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.

  2. #77
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    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.
    yeah, but i don't think people realize just how slow compiling native PHP is. 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

  3. #78
    SitePoint Enthusiast wogboy's Avatar
    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!

  4. #79
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    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!
    oh, i know. 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.

  5. #80
    SitePoint Enthusiast wogboy's Avatar
    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.

  6. #81
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  7. #82
    Super Ninja Monkey Travis's Avatar
    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.
    Travis Watkins - Hyperactive Coder
    My Blog: Realist Anew
    Projects: Alacarte - Gnome Menu Editor

  8. #83
    SitePoint Addict MarekS's Avatar
    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 think it's not bad at all. Few control structures (as a presentation logic) is perfectly valid in a template - as mentioned many times before.

    I have to say that I feel damn good if there is not a single echo in my business layer Templates 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.

  9. #84
    SitePoint Wizard silver trophy redemption's Avatar
    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.
    On the contrary, Smarty templates are the fastest templates AND also support one of the most (if not the most) features.

    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?

  10. #85
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally 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
    Real men code in binary

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  11. #86
    Talk to the /dev/null Theiggsta's Avatar
    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.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  12. #87
    SitePoint Member
    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.

    Quote Originally Posted by voostind
    I seriously believe that template engines like Smarty are a complete waste of our precious time.
    It is a waste only if you're using it without knowing how to use it, we'll get back to it later, pointing on the "good stuff" of Smarty.

    They do not add any features to PHP not already there
    Imho, Wrong. The most obvious answer is that Smarty is provided with "tags" that are not provided "as is" in PHP. Of course you can get the same with home made php functions, but they are provided with Smarty. (so, don't waste time, use Smarty tags)

    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.
    I would only say that template engines are "a way of" separating business logic and presentation logic. They also provide tools "designed for" the presentation logic.

    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!"
    You were right, I am in fact saying this :-)

    That is not true.
    Hope I'll get you wrong ;-)

    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.
    Yes, PHP has all the features that are in Smarty, but it takes you several lines to get the same result.

    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?
    Because it's a ready to use "presentation framework".

    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.
    No, plain HTML is the structure of the document. (h tags are the titles, p paragraphs, ....). The content is things that are between the tags.

    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 think that people who are using template engines are well aware of why they are using it. People who don't care about logic separations just don't care about template engines.

    I have been programming now for
    Yeah, me too, and i wrote a lot of PHP applications, from 100 lines to 50 000+.... all of them are using Smarty and are happy with this.

    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.
    With even less efforts, use Smarty, it's all here :-)

    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.
    Well.... to be correct, Smarty has a "rendered html pages" cache.
    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 ]

  13. #88
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gerald
    [EDIT: LOL i didn't notice how old the post was..... sorry ]
    Well, since 2.6.3 is out and the topic says 2.2.0 released, at least this should have given you some hints
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  14. #89
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gerald
    [EDIT: LOL i didn't notice how old the post was..... sorry ]
    This topic kind of morphed into template engines vs. php. I think your post is really good and still relevant.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  15. #90
    SitePoint Guru
    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 } ?>
    That's pretty simple right? And why not:
    <?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

  16. #91
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mwmitchell
    That's pretty simple right? And why not:
    <?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?
    Both those examples are perfectly logical, I think. However, you'd have to code both of them yourself.

    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?

  17. #92
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    Both those examples are perfectly logical, I think. However, you'd have to code both of them yourself.

    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.
    If you can imagine Smarty without the special syntax, that what php is. You could easily build a set of classes that have built in 'plugins' to do common view tasks for you. If it needs to change for a particular situation, extend the class and implement your own method.

    Quote Originally Posted by samsm
    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.
    I have 'view' classes that handle view/presentation logic. My templates are basically *very* 'dumb' and do almost only printing, and sometimes looping. And I don't think graphic designers should/want to touch any code. They're graphic designers.

    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

  18. #93
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    However, you'd have to code both of them yourself.

    Smarty has taken a number of very common presentation techniques and done them for you, that is its draw.
    Both has it's pros and cons

    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.

  19. #94
    SitePoint Guru
    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

  20. #95
    SitePoint Wizard samsm's Avatar
    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?

  21. #96
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mwmitchell
    Hey, http://phpsavant.com/ is one way it can be done.
    Right, that's similar to what came out during my work, a collection of usefull functions/classes.
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  22. #97
    SitePoint Wizard megamanXplosion's Avatar
    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;
    }
    
    
    
    
    }
    ?>
    Then you use the template class like this...

    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.

  23. #98
    SitePoint Member
    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
    Regards, Valics Lehel
    http://www.grafxsoftware.com

  24. #99
    SitePoint Member
    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.....

  25. #100
    SitePoint Enthusiast
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •