How do web templates separate content and logic?
johnjsal at gmailNOSPAM.com
Sun Jun 29 05:18:30 CEST 2008
bruno.desthuilliers at gmail.com wrote:
> For which definitions of "content" and "logic" ???
> The point of mvc is to keep domain logic separated from presentation
> logic, not to remove logic from presentation (which just couldn't
> work). Templating systems are for presentation logic. Whether they
> work by embedding an existing complete programmation language or by
> providing they're own specialised mini-language (or a mix of both) is
> not the point here IMHO.
No, I don't mean presentation logic at all. I mean something along the
lines of combining HTML (which is what I refer to as "content") and
Python (which is what I meant by "logic"). So for example, if you have
code like this (and this isn't necessarily proper code, I'm just making
this up, but you'll see what I mean):
<h1>Big Important Topic</h1>
<p>This is where I say something important about</p>
% for topic in topics:
Humph, I just made up that example to make the point that when you no
longer have pure HTML, but instead have programmatic logic (Python)
mixed in with the HTML, then you are mixing content and logic.
However, as soon as I finished typing it out, it occurred to me that
even the so-called logic in this example is really only producing more
"content" to display.
So maybe my question was a little premature. Or could it just be that
this is a *good* way to mix HTML and Python, and there are other ways
which may be bad? (For example, connecting to a database, like
Sebastian's example. That definitely seems out of place in an HTML file.)
More information about the Python-list