Been interesting to watch this discussion.
I started off anti template engines but now I'm less so.
The security issues - for example a multiple user CMS or a team of people working on a site whose "permissions" you want to restrict to only what is essential for their job - was something I hadn't thought of.
The smarty paradigm (I think) compiling templates on their first use so they don't have to be parsed on every page load would pretty much remove any objections about efficiency.
I also objected to loops in templates - but, as mentioned in smarty docs, that's presentation logic not business logic and it makes sense to have that in a template.
Still, you'd have to think about the end user: if you build sites for small to medium organisations, you often find that they have (at best) a weak grasp of html: expecting them to cope with a template language any more complicated than a simple {var here} could be too much. Bigger enterprises and more experienced designers would probably be OK with that though.
I suppose this isn't specifically a template engine issue. Instead of template engine loop code, you could use output buffering in the php and a second, mini-template to create a single output var containing rows (forum posts for example). Whether you are parsing with a template engine or simply including html templates you have the same choice to make: one catch-all template with loop code or a main template, buffering & mini-templates with no loop code. Which way to go, I would suggest, depends on the skill level of whoever will be maintaining the live site.
I've recently been re-writing all my code so that all scripts finish with an array of output vars (used to be a real mess with stuff echo'd out all over the place). For the moment I'm extract()'ing these then including html templates where they are all echo'd out, but it would be easy to stick a template engine on the end if required for a particular job.
HTML Templating class for PHP - Please try it /give feedback
Moderator: General Moderators
Well, but I don't understand exactly about template language. Ok, simplest and real exampe: navigation bar. In my scheme, user (i.e designer) should fill array:
$navbar=('home'=>'index.php',
'feedback'=>'feedback.php',
'my bees'=>'mybees.php'
);
It also has php function (or obect, no matter) to draw:
function DrawNavBar($items,$prop) {}
i.e.
$props=(
'direction' => vertical,
'class' => 'mymenu',
'caption'=>'Main'
);
So if I use simplest template with php inclusions, designer just includes
<?php echo DrawNavBar($items, $props)?>
and site\template engine is finishing by:
include "layout.htm"
How are you going to do it with your engine?
$navbar=('home'=>'index.php',
'feedback'=>'feedback.php',
'my bees'=>'mybees.php'
);
It also has php function (or obect, no matter) to draw:
function DrawNavBar($items,$prop) {}
i.e.
$props=(
'direction' => vertical,
'class' => 'mymenu',
'caption'=>'Main'
);
So if I use simplest template with php inclusions, designer just includes
<?php echo DrawNavBar($items, $props)?>
and site\template engine is finishing by:
include "layout.htm"
How are you going to do it with your engine?
The idea of templates is good, but isn't good enough for large web portals with 400+ pages where the designers & logic programmers are completely different having their own work ques, having to develop independantly.
I think PHP requires a complete framework to seperate HTML and dynamic logic without introducing new tags or includes in the HTML page... we are designing such a system http://www.cse.mrt.ac.lk/~nabeelmy/phplus/ where the HTML page will be standard HTML and everything will be manipulated using the 'id' attribute in the tags (by using DOM parsing).
this is still in the design phase... send comments to phplus@cse.mrt.ac.lk
thx
Wolfie
I think PHP requires a complete framework to seperate HTML and dynamic logic without introducing new tags or includes in the HTML page... we are designing such a system http://www.cse.mrt.ac.lk/~nabeelmy/phplus/ where the HTML page will be standard HTML and everything will be manipulated using the 'id' attribute in the tags (by using DOM parsing).
Code: Select all
<p><span id="MyTxt1">your dynamic text</span></p>
<a href="#" id="MyUrl1"><span id="myurlTxt">url text</span></a>
<table>
<tr id="MyTemplateRow">
<td><span id="MyCellTxt">some text</span></td>
</tr>
</table>thx
Wolfie
to wolfie 2x.
Yes, it's clear. You can use DOM scheme, as well as XML or named anchors to mark you template. The only question arises - if you parse your template code from your own template language - why do you need in creating intermediate PHP classes? You can do everything sraightforward from DOM to HTML in C++ with ASAPI, CGI etc...
Anyway good luck in your work.
Yes, it's clear. You can use DOM scheme, as well as XML or named anchors to mark you template. The only question arises - if you parse your template code from your own template language - why do you need in creating intermediate PHP classes? You can do everything sraightforward from DOM to HTML in C++ with ASAPI, CGI etc...
Anyway good luck in your work.
Most template engines leave the designer to use loops and such, but I took a different approach when creating my template engine. Sure you can easily replace {SOMETHING} with "blah blah blah", but the real advantage is this:
Looping a file several times into a tag like {BODY}. I've written it all up here for the sake of not typing more:
http://www.sitepointforums.com/showthre ... did=118958
Looping a file several times into a tag like {BODY}. I've written it all up here for the sake of not typing more:
http://www.sitepointforums.com/showthre ... did=118958
I may be stupid but:
While i was creating a localisation system for my framework i thought:
Why not remove all but allowed php calls from the templates?
I have 1 class that maintains a localisation file based on thefunction calls made in the templates.
The command line interface for this class lets you create new languages and update already existing once.
Why not remove all php calls that i are not allowed while im at it?
..... just a thought
Im have been using templating systems for a long time and the only problem i found with not using them is the security.
php in the design just makes me a lot happier but i dont want stupid designers to do silly things. Would be nice to limit them to:
Now ive choosen to go no template system all the way and will try to implement this remove dangerous code from the templates.
I mean for me templating is a way to separate business logic from gui logic. And dont want to implement an other layer just for the design.
Any thoughts?
Why not remove all but allowed php calls from the templates?
I have 1 class that maintains a localisation file based on the
Code: Select all
<?php translate()?>The command line interface for this class lets you create new languages and update already existing once.
Why not remove all php calls that i are not allowed while im at it?
..... just a thought
Im have been using templating systems for a long time and the only problem i found with not using them is the security.
php in the design just makes me a lot happier but i dont want stupid designers to do silly things. Would be nice to limit them to:
Code: Select all
<?php
run('module');
translate('String');
print('String');
And some html functions that i might want to add.
?>I mean for me templating is a way to separate business logic from gui logic. And dont want to implement an other layer just for the design.
Any thoughts?