On 12/21/06, Jamie <[EMAIL PROTECTED]> wrote:

I'm new to Python and even newer to the Python frameworks, but I'm an
old hack at web development. I've been evaluating the various
frameworks and was struck my how different Myghty is compared to Kid,
Django's template system, or even PHP's Smarty.

Unless I'm misunderstanding something, there doesn't seem to be a way
to make a Myghty template without embedding Python? The "<%" syntax
reminds way too much like the spaghetti code I'd expect to see in a
.php file. Why is Myghty considered a templating framework when the
logic is unavoidably intermixed with the presentation?

There are template libraries with no logic at all.  I ported one from
PHP that had only placeholders and blocks.  There was one global
namespace (a flat dictionary).  To do for-stanzas you created a block
containing the loop body, and a "target" placeholder to receive the
loop's final output.  Filling the template went like this:

1. Call a method to extract the named block to a variable.  (Removing
it from the template.)
2. Set the substitution variables for the first iteration.
3. Call a method that fills the mini-template in the block variable
into the target variable.
4. Set the substitution variables for the second iteration.
5. Call the method to fill the mini-template and append the result
into the target variable.
6. Repeat 4-5 for all iterations.
7. Fill the main template.

If-stanzas were handled similarly.  I found the library very strange
and non-intuitive, but it was PHP's "state of the art" at the time.  I
think it had been ported from Perl.  Needless to say, nobody uses
template systems like that now.

All current Python template libraries emphasize the distinction
between "business logic" (model/controller) and "presentation logic"
(view).  Only the latter should be in the template.  The libraries
differ in terms of how much logic they allow, and how different the
syntax is between logic and placeholders.  Myghty keeps the
distinction very close.

The reason many template libraries allow arbitrary Python statements
as logic is to handle situations the template developers didn't
foresee.  As one of the developers of Cheetah, I've seen it being used
in ways I've never imagined.  I was initially opposed to adding
directives in Cheetah for every Python statement, but time has proven
me wrong.  Sometimes I've even used  #raise, #return, #break, and
#continue.


--
Mike Orr <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to