Reputation: 41847
Since I keep showing up late for answering questions tagged php where i actually know the answer i figured i'd try asking a question myself.
I've been working on so many complete rewrites of a custom template engine in php for so long and so many times that i thought i'd ask for opinions.
In short, this is the most important part i have implemented so far:
IView
compatible class instance ( IView
defines a Render()
method)
sprintf('//%s:*[@runat="server"]', $namespaceprefix )
$tag.localName
and instantiates one and attaches it to the original template.main()
the handler, which renders it.I am basing my template on xml. a simple template currently looks like:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:red="http://www.theredhead.nl/serverside">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title will be filed by the View depending on the Controller</title>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Main/" />
</head>
<body>
<!-- the entire body may be reset by the view using it, using XPath and DOM functions -->
<!-- Usually the PageHeader and PageFooter would be put back after clearing the body -->
<div id="PageHeader">
<img src="/Image/Get/theredhead_dot_nl.png" alt="Site Logo" />
</div>
<h1>www.theredhead.nl :: Test Template</h1>
<p>
Lorum ipsum dolar sit amet. blah blah blah yackadee schmackadee.
</p>
<div id="PageFooter">
Built by
<br />
<red:UserProfileLink runat="server" Username="kris" />
</div>
</body>
</html>
At current, this outputs (including the broken indentation):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:red="http://www.theredhead.nl/serverside">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Welcome to my site</title>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Main/"/>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Custom/"/>
<link rel="stylesheet" type="text/css" href="/Stylesheet/Get/Profile/"/>
</head>
<body>
<!-- the entire body may be reset by the view using it, using XPath and DOM functions -->
<!-- Usually the PageHeader and PageFooter would be put back after clearing the body -->
<div id="PageHeader">
<img src="/Image/Get/theredhead_dot_nl.png" alt="Site Logo"/>
</div>
<h1>www.theredhead.nl :: ModelViewController</h1>
<p>
Lorum ipsum dolar sit amet. blah blah blah yackadee schmackadee.
</p>
<div id="PageFooter">
Built by
<br/>
<div><div xmlns:profile="http://www.theredhead.nl/profile" class="ProfileBadge" style="font-size : .8em;">
<a style="text-decoration : none; border: none;" href="/Profile/View/kris">
<img style="float : left;" src="http://www.gravatar.com/avatar/5beeab66d6fe021cbd4daa041330cc86?d=identicon&s=32&r=pg" alt="Gravatar"/>
 Kris
</a>
<br/>
<small>
 Rep: 1
</small>
</div></div>
</div>
</body>
</html>
So the big question is: Do you have any input on must-have functionality?
P.S. if anyone is interested in the complete source-code, please leave a comment, I will be providing it on my site when I reach reasonable developer usability levels.
Upvotes: 1
Views: 1855
Reputation: 41847
Seems to me only Phil Reif actually read and understood the question and its intention.
Those people claiming php is the template engine and that's that are ignoring too many facts and have blinded themselves from the real world where solid frameworks are important.
So, the points must have features so far (that haven't already been implemented) are:
<asp:DataGrid>
<?php ... ?>
is a valid xml DOMProcessingInstruction node, but the judges are undecided.I've set the first drafts online so you might take a look and maybe get back to me with some neat ideas.
By the way things look i'll have forms up and running in the next couple days. At the moment it's only a first draft of a design (both code and style wise)
Still hoping for some more input here, what kind of controls do you people use and love? (from any framework/language)
Kris
Upvotes: 1
Reputation: 7789
Here's an article on templating engines: http://massassi.com/php/articles/template_engines/
You're doing it wrong.
Upvotes: 1
Reputation: 9401
Why not just use PHP as your templating system. PHP IS the template system.
What is wrong with just dumping <?php=$variable;?>
in an HTML template? You can use foreach loops, etc.
Just make sure that you run it from within a scope that cannot access any variables you do not want.
I have a really deep founded hate for overcomplicated template systems like this since my Java/Struts nightmares. You have to dive into namespaces, xpath, custom namespaces and all that stuff before you can change just the one thing you need.
Upvotes: 6