RainTPL for FAST Templating
Hi All, not the usual, "how can you help me" thread, but a heads-up on a templating engine I've been using for a while called RainTPL. A few users have posted threads of late asking about templates.
I thought I'd give this one a plug, especially as Federico (the author) has just published a speed test page on his site: http://www.raintpl.com/PHP-Template-Engines-Speed-Test/
If you've used templaters like Smarty, RainTPL should seem very simple to use - just "8 tags and 2 methods".
If you're interested, I've documented a multilingual implementation at diafol.org/rain.php , which is itself built on RainTPL.
Anybody have any views on RainTPL or any other templater?
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
For me, RainRpl is a valid option for a new site. The trouble of switching existing sites is not one I wish to take. Not because it is hard, but I'm just too lazy. I'm so used to my own set of tools, it's the first thing I copy.
Next to that, is the fact that I do not always make my own design. Some of the designers also have grown used to smarty (and the plugins I use).
All in all, I think it is a very nice templating engine to start using.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
I spent a bit of time with RainTPL the last time that Ardav mentioned it in a post and I agree that it is pretty simple and straightforward. I would certainly consider it for something new. Retrofitting it would need some meaningful payback to make it worthwhile.
chrishea
Nearly a Posting Virtuoso
1,429 posts since Sep 2008
Reputation Points: 210
Solved Threads: 230
A bit disappointing... I really expecting this to turn into half a flamewar, or at least something interesting. Apparantly nobody with opinions here.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
Yep, bit of a damp squib. Thought it would generate some discussion wrt. template engines.
I used to use Smarty, but I found it too cumbersome. How's that for a start?
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
I've done XSLT's too. Mostly when using MSSQL, because it can output data as XML. Directly mapping your query result onto an XSLT was something I really liked.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
{loop name="arrayname"}
<option value="{$value}">{$value}</option>
{/loop}
against
<?php
foreach($arrayname as $item){
?>
<option value="<?php echo $item;?>"><?php echo $item;?></option>
<?php
}
?>
or
<?php
foreach($arrayname as $item){
echo "<option value=\"$item\">$item</option>";
}
?>
or any myriad other combinations. Have to say, not much difference in 1 and 3. 2 is just silly. However, I do like the idea of not having php tags in my html.
XSLT - had a go at this a while ago, never got into it. Perhaps it's worth another look? Is it worth it for simple pages that just need the odd loop, include and variable placeholder (e.g. traditional templater)?
Although the functionality of XSLT has been listed, is it a viable option for general practitioner or enthusiastic hobbyist (like myself)? Or is it more for professional standard programmers?
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
**Sorry, but forgot to ask. I know XML can be used as a data store for XSL, but can XSLT deal with DB too? From what I gather mysql has to form xml data first. If so, isn't this a bit fiddly? I'd rather keep my data in a DB without having to dump it to XML and then parsing it into XHTML via XSLT.
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
@ms
Thanks for that. I was just wondering whether XSLT can grab data from mysql or does everything have to pass through xml? I had a little go with xquery a while back, but I couldn't understand what advantage holding data in xml has over a mysql db.
Excuse my ignorance. I'm just trying to get to grips with why store data as xml in the first place (other than the obvious universal format).
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
OK, I think I got you. As I assumed, the xml is just a temporary snapshot of the data 'as is/was' from the DB. So you'd still need the DB as your main data store. Updating the DB would be via php mysql (or other DB) functions I assume - you wouldn't use xml as an intermediate for DB updating/insertion?
You've given me food for thought. I may consider using xslt in my next mini project.
Thanks again.
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
I looked at RainTPL and pretty quickly I got it. I played with it and tried a few things and they worked. It will take some more time to get any good with it but it doesn't seem difficult or intimidating. I have one application where I think it might be beneficial but I'm not sure if the retrofit effort would be worth it.
Previously, I tried to understand Smarty and I never got there. With more time I probably would but I didn't have a compelling need so I didn't pursue it. Just had a quick look at XSL/XSLT and it seems a bit like the Smarty situation. With some time I can probably figure it out but I'm not really sure that it's worth it (and still no compelling reason).
Thus, for potential occasional use, I think that RainTPL is the winner based strictly on simplicity. If I was to use a template system for every new project then there might be more capabilities in XSL or Smarty that would make one of them a better choice. I understand that there is some theoretical benefit in separating the view part from the logic and variables but I'm not sure if there is a real payback to make it worthwhile. Any thoughts on (real) benefits?
chrishea
Nearly a Posting Virtuoso
1,429 posts since Sep 2008
Reputation Points: 210
Solved Threads: 230
I think the real benefit is only when you allow the user to modify/switch templates on the fly. One nice example would be a simple report generator using mssql (which outputs xml) in combination with a query builder and an xslt. Both the query and the xslt were stored in the db, and so could be easily changed to suit new needs.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
The example of the vendor was nice. I probably won't need it (yet).
The advantage of template placeholders {$var} vs. <?php echo $var;?> I suppose is a personal thing. It at least does away with the "do I enclose html in my php output or do I shove in loads of php snips into my html?". I always found it really unsatisfactory to see php and html all over the place. OK, it can be argued that the php hasn't really been removed, just replaced by a series of placeholders, but for me that in itself is an improvement. Uncluttered HTML.
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Just received a PM from OcRedF - thanks mate - describing speed tests conducted with the leading templaters vs. php. Really interesting. Seems RainTPL is really fast:
http://www.phpcomparison.net/
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080