
Originally Posted by
aamonkey
That's great, but it doesn't require a (second) parser to accomplish this. You can just assign values to variables using whatever logic you like in your business logic layer, and pass those variables to the templates. It's essentially exactly what you are describing - without the extra overhead and without the need to learn a custom syntax. Why not use php for what it is best at?
1) You can skip that binding logic entirely.
2) and more importantly it lets you easily abstract away common display logic (see the pagination example).
3) It lets you have total control over what's possible without working PHPs syntax around it. For instance, I use code like this:
PHP Code:
<tabsheet>
<tab name="Tab 1">
<h1>This is tab 1</h1>
<p>foo</p>
</tab>
<tab name="Tab 2">
<p>tab 2</p>
</tab>
</tabsheet>
Which is automatically translated into something like this:
PHP Code:
<div class="tabsheet" id="tabsheet1">
<ul class="tabheader">
<li id="tabsheet1_1 current">Tab 1</li>
<li id="tabsheet1_2">Tab 2</li>
</ul>
<div class="tabpage current" id="tabsheet1_page1">
<h1>This is tab 1</h1>
<p>foo</p>
</div>
<div class="tabpage" id="tabsheet1_page2">
<p>tab 2</p>
</div>
</div>
Which displays a set of tabs and pages that maps directly into my existing CSS and javascript and just *works* without any messing worrying about attaching the javascript events, getting element ids/names right. All the generation logic is abstracted away and even supports nesting. It makes for very fast built templates. I have various other components including a headed, potentially draggable box which I just use <box title="Box">Contents</box> rather than multiple divs. If I need to change the way the box is drawn, it's its own template in one and it will affect the site globally. I have similar componentalised form generation. Where this is especially useful is for mobile browser versions.
I'm also wondering why use the extra parsing layer. Supposing your proposed 'returning user' and 'unregistered user' are what we want to check for then why instead of:
This requires knowledge that things may change regarding that condition. What if that changes to $user->isReturning() && $forum->minAccountAge < $user->accountAge()*. My point is, you can't know how things will change. As I stated previously, it's the equivalent of CSS stylesheets vs inline styles. I can essentially update the "stylesheet" (the logic) in one place and affect everything.
*Again, think beyond this trivial example to real-world scenarios where things do change all the time.
Bookmarks