design of outline

0 views
Skip to first unread message

mbis...@googlemail.com

unread,
May 20, 2008, 8:40:23 AM5/20/08
to php-outline
Hi there,

I stumbled over your template engine some time ago and think it is
quite nice. However, there is one thing that irritates me. You say
"this engine tries to leverage the power of the template engine you
already know: php." Why do you bother to create yet another syntax for
it then?

I see two big advantages to template engines. They help to separate
business logic from user interface considerations, and handle caching.
An easier syntax _can_ be an advantage, but aren't the php developers
you target used to the syntax anyways?

Yours,
mbisotti

mindplay.dk

unread,
May 20, 2008, 9:26:23 AM5/20/08
to php-outline
Hello,

To answer your first question first: I invented very little new syntax
for Outline. That's one of the major differences between Outline and
other template engines - it tries to stick as closely to existing php
syntax as possible. Where Outline syntax deviates from php, is where
php is too complicated or illegible to be practical or convenient for
simple view-implementation tasks.

If it didn't do that, it wouldn't need to do anything at all - you
could just use a caching engine and straight php templates without an
engine.

To your second question: template engines do not help you separate
business logic from the interface - this is a common misconception.
With engines like Outline and Smarty, for example, there is nothing
preventing you from calling arbitrary php code anywhere in your
templates, or passing in objects as template variables and invoking
their methods - so ensuring good separation is entirely up to the good
(or bad) judgement of the developer.

Whether you're used to php syntax or not, typing <?php echo
$something ?> is invariably more work than just typing {$something} -
straight php-templates are a lot more cluttered and less legible
because of this inconvenient syntax.

In my experience, if you can make your code more maintainable, and
reduce development time, and this does not come at the cost of a
significant performance penalty, that's a good thing.

For someone who knows php, learning Outline will take about 20 minutes
of effort. That time will be well invested if every view you implement
takes you about two-thirds of the number of keystrokes it did before -
and fewer keystrokes means fewer typos to correct along the way.

For these, and other reasons listed on the website, I think a template
engine of this type is well justified and well worth the effort.


On May 20, 2:40 pm, "mbiso...@googlemail.com"

mbis...@googlemail.com

unread,
May 20, 2008, 12:36:51 PM5/20/08
to php-outline
Hi again,

thanks for your detailed answer.

You are right that template engines do not enforce any separation
technically,
though they psychologically help the considerate programmer ;-)

Oh and don't get me wrong, I perfectly see the use of your template
engine,
in fact I've used and am using Smarty quite a lot. What annoys me is
that you need
to rely on builtin functionality if you don't want to "break out" of
the syntax.
Example? You would have to write a plugin for Smarty to mimic PHP's
implode function
to be able to use it as a modifier.

Anyways, I will definitely check out Outline and give you some
feedback.

mindplay.dk

unread,
May 20, 2008, 1:49:47 PM5/20/08
to php-outline
Yes, with commands like implode() you need to write a wrapper-
function, if you want to use it as a modifier. In Outline you have a
few options - one is to write a simple wrapper function:

function outline__implode($array, $glue = ', ') {
return implode($glue, $array);
}

You don't have to register that or do anything else, just make sure
the function is loaded when you render your template, and it'll work
like this:

{$myarray|implode:' - '}

would produce: "a - b - c" etc.

You can also call php functions directly, if you prefer, e.g.:

{#implode(' - ', $myarray}

The # command lets you execute any php function, using php syntax, and
echo it's return value. You don't need the outline__implode() function
if you choose this method.

If you prefer your templates to be closer to straight php, you can
actually just use this command all way round - any php function can be
called using {#xxx} syntax, doesn't have to be function calls either,
you can use any standard php expression, e.g.:

{#$a.strtoupper($b).'/'.md5($c)}

The ternary operator is sometimes handy as well, e.g.:

{$numfiles} {#$numfiles == 1 ? 'file' : 'files'}

Think creatively :-) ... what's great about Outline, in my own
opinion, as compared to other template engines, is the ability to use
any php expression/function anywhere you please. There's a lot you can
do with standard php out of the box, that's why Outline itself
implements so few commands and modifiers - pretty much everything you
need is already in php, it's just much easier to get to it this
way ;-)


On May 20, 6:36 pm, "mbiso...@googlemail.com"

mbis...@googlemail.com

unread,
May 20, 2008, 5:23:11 PM5/20/08
to php-outline
On 20 Mai, 19:49, "mindplay.dk" <mindplay...@gmail.com> wrote:
> the ability to use any php expression/function anywhere you please.

That rules!
Reply all
Reply to author
Forward
0 new messages