[wp-hackers] Easytags template system

Tom Armitage tom.armitage at gmail.com
Wed May 10 10:52:22 GMT 2006


To my mind, the purpose of a templating system is to hide the application
logic and provide a simple way of substituting and iterating through data
objects.

Wordpress doesn't have a templating system. At all. Right now. It has inline
PHP. Regardless of whether or not you thing this is a good thing from a
grokking perspective (and I don't, because PHP syntax is very, very fussy
and glyph-heavy compared to HTML, which isn't good for newbiews), it's a bad
thing from a templating perspective because it encourages crappy code.

Like putting SQL or ez-SQL requests inline in a template. Ouch. Use a
plugin! Use the APIs!

The loop is probably the least intuitive thing in Wordpress's theme engine
right now. That's because it exposes how the code is understood by the
interpreter, and not how it's understood by humans. So: MT's
<MTEntries><MTEntry>...</MTEntry></MTEntries> makes a lot of sense to
non-programmers. Here's a block of "Entries", and here's the sample layout
for a single "Entry". The template works the way I imagine it. The parsers
then finds MTEntries and substitutes it with a foreach loop.

So, in a true templating system, you wouldn't directly put a "simplified
version" of loop code in. You'd just put <$wp_posts$>...foo...</$wp_posts$>
or something.

So now we run into problems. Any templating engine is going to end being a
reduction of what's possible in straight-up PHP. There are a couple of
obvious options:

limit what "easytags" can do and say "look, if you want to do
complex/non-standard stuff, use inline PHP" [I think this is bad because
inline PHP is bad]
find a way of using PHP and easytags in the same template [better, but
complex]
somehow make easytags do EVERYTHING [unlikely].

Basically, it's an executive decision about the direction of the project -
should easytags be for one user and inline-PHP for another, or should both
be options? I think "easy" is poor nomenclature, because it implies
"newbie". It's not about making things simpler. It's about giving Wordpress
a proper templating syntax.

Regarding ease-of-use: most people coming to Wordpress new know some HTML.
If you've come from Blogger, you know some HTML. Maybe not enough to design
a theme from scratch, but enough to fiddle with what's inside it. If you've
managed to install Wordpress, you probably enough HTML competency to use
quicktags. PHP has _very strange syntax_ compared to HTML, because it is not
a templating language. All the brackets, the semi-colons, seperating
arguments with commas right; there's so much to get wrong! And smattering it
through a document inline leads to messy code - and also makes it hard for
new people to understand. I mean, complex inline PHP documents are hard for
anyone to parse (compared to a nice single piece of code and a Smarty
template).

I think quicktags/easytags/whatever are definitely easier to grok if you're
smart enough to run blog software. As i said, though, it's not about
easy/hard. It's about doing templating right. It's about letting all the new
users know that you shouldn't drop SQL inline just because you can.
Currently, if you don't know PHP, messing around with WP themes is likely to
lead to you writing _crappy code_. WP should foster its users, no matter
what their competency, and by encouraging true templating, more people are
going to use plugins and the API as they're intended. So I think it'd be
good for the project as a whole.

And yes, before I get flamed to fuck, I'm aware that PHP was designed as a
templating engine. But it _isn't any more_.

t.


On 10/05/06, Sam Angove <sam at rephrase.net> wrote:
>
> On 5/10/06, Matt Mullenweg <m at mullenweg.com> wrote:
> >
> > Basically the concept is that it's very easy to parse something like
> > <$the_title$> into <?php the_title(); ?>. What if there was a plugin (or
> > in WP core) an option that gave you a "friendly" view when editing
> > templates? On display it could hide all the scary PHP it knows how to
> > parse behind psuedo-HTML tags, and on save turn it back into the PHP
> > that WordPress knows and love.
>
> Is it going to know both:
>
> <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
>
> and
>
> <?php if (have_posts()) : ?>
>
>         <?php while (have_posts()) : the_post(); ?>
>
> ? (From the classic theme and Kubrick, respectively.)
>
> What about the various deprecated loop syntaxes, and all their
> variants of spacing and punctuation? What about plugins?
>
> It's not going to understand every code snippet and plugin function,
> so many/most themes are going to be a confusing morass of PHP and
> "easytags" all mixed into one. That sounds rather worse than the
> system now.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list