473,883 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: How do web templates separate content and logic?

On 27 juin, 18:09, "John Salerno" <johnj...@NOSPA Mgmail.comwrote :
I've been doing some research on web templates, and even though I read that
they help enforce the MVC pattern, I don't really understand how they are
keeping content and logic separated.
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.
Layout is easy, it's just not there as
far as I can see, and CSS can be used for that.
You still have to generate the markup on which css will be applied,
don't you ?
But when you have a templating system that mixes HTML and Python code, how
is this helping to keep things separate? It seems to be the same issue that
some people have with PHP (that it is too integrated with the HTML, rather
than being separate).
Well... yes and no. The server page approach surely fails to make
clear what belongs to which layer. Now you still can produce "clean"
application using PHP - if you are disciplined enough and know what
you're doing. It's a bit like the "lack" of language-enforced access
restriction in Python - it's only a problem if you don't understand
why it's good to separate interface from implementation.
Of course, I suppose whether or not any of this matters depends on if you
are a web designer or a programmer, but am I missing something about
templates, or is it really the case that they, more or less by definition,
combine content and logic?
The real problem is not to avoid having logic in templates, but to
avoid mixing domain logic (which is independant from presentation) and
presentation logic. Using a templating system - whether it embeds
Python or use it's own mini-language - makes clear (well... clearer)
what belongs to presentation and what belongs to domain.

Jun 27 '08 #1
15 2451
br************* ****@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):

<body>
<h1>Big Important Topic</h1>
<p>This is where I say something important about</p>
<ol>
% for topic in topics:
<li>${topic}</li>
</ol>
</body>

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.)
Jun 29 '08 #2
John Salerno <jo******@gmail NOSPAM.comwrote :
>
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):

<body>
<h1>Big Important Topic</h1>
<p>This is where I say something important about</p>
<ol>
% for topic in topics:
<li>${topic}</li>
</ol>
</body>

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.
Technically, you are probably right, but a model like MVC is supposed to
enable better programming. It's not intended to be straightjacket and
handcuffs. If that snippet makes sense to you, then there's nothing wrong
with it.

What's the alternative? The alternative is to have your Python code do
something like this:

topicList = []
for topic in topics:
topicList.appen d( topic )
topicList = '</li><li>'.join( topicList )
and have your HTML page be:
<ol>
<li>${topicList }</li>
</ol>

but now I've put chocolate into my peanut butter by embedding <litags in
my Python code.
>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.)
If it seems out of place to you, then you shouldn't do it. In general, you
need to find a model that makes sense to you, and that allows you to write
readable, workable, maintainable code.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 30 '08 #3
has
On 29 Jun, 04:18, John Salerno <johnj...@gmail NOSPAM.comwrote :
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").
[Note: if you're not familiar with MVC, best go read up on it now
otherwise none of this thread'll makemuch sense.]

As Bruno says, the goal of most templating engines is to separate the
business portion of your application from the user interface portion,
basically slicing along the existing Model/View divide in the commonly
used (Model-View-Controller (MVC) application design pattern.

However, if you want a finer-grained divide between HTML markup and
presentation logic within the View layer itself, there are a few
templating engines that support this: PyMeld, HTMLTemplate (mine),
Nevow. These keep the Python-based presentation logic completely
separate from the HTML-based presentation markup, relying on simple
tag attributes to identify HTML elements can be manipulated
programmaticall y.

The initial learning curve's a bit steeper for these engines due to
the higher level of abstraction, but once you get your head around the
overall concept they're quite simple to use since you don't have to
learn a separate mini-language, write Python code in an HTML editor,
or anything like that.

HTH

has
Jun 30 '08 #4
John Salerno a écrit :
br************* ****@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").
Some (if not most) templating systems use their own mini-language to
handle presentation 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):

<body>
<h1>Big Important Topic</h1>
<p>This is where I say something important about</p>
<ol>
% for topic in topics:
<li>${topic}</li>
</ol>
</body>

In Django's template system, this would looks like:

<body>
<h1>Big Important Topic</h1>
<p>This is where I say something important about</p>
<ol>
<!-- no, this is not Python -->
{% for topic in topics %}
<li>{{ topic }}</li>
{% endfor %}
</ol>
</body>

In ZPT, it would be:

<body>
<h1>Big Important Topic</h1>
<p>This is where I say something important about</p>
<ol>
<tal:repeat repeat="topic topics">
<li tal:content="to pic">Yadda</li>
</tal:repeat>
</ol>
</body>

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.
Indeed.
So maybe my question was a little premature.
The meme "thou shall not mix domain logic with presentation" is very
often misunderstood as "you must not have anything else than html in
templates", which is just plain non-sense. Even declarative templating
systems (cf Has's post) require some special (ie: non standard) stuff to
work.
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?
Bingo.
(For example, connecting to a database, like
Sebastian's example. That definitely seems out of place in an HTML file.)
Yeps.
Jun 30 '08 #5
On Jun 30, 10:57*am, Bruno Desthuilliers <bruno.
42.desthuilli.. .@websiteburo.i nvalidwrote:
>
Some (if not most) templating systems use their own mini-language to
handle presentation logic.
IMHO this is the funniest (worst) part of all this 'templating'
buss :)
It reminds me the good old slogan: "Have you invented your own GUI
library yet?"
>
The meme "thou shall not mix domain logic with presentation" is very
often misunderstood as "you must not have anything else than html in
templates", which is just plain non-sense. Even declarative templating
systems (cf Has's post) require some special (ie: non standard) stuff to
work.
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?

Bingo.
Then what is so *good* about it, why embedding HTML into Python is not
good?

Mikhail

+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++
++++++
Q: What one would get after crossing a snake and a hedgehog?
A: A barbed wire metre.
Jun 30 '08 #6
On Jun 30, 1:19 pm, Mike <ter...@gmail.c omwrote:
On Jun 30, 10:57 am, Bruno Desthuilliers <bruno.

42.desthuilli.. .@websiteburo.i nvalidwrote:
Some (if not most) templating systems use their own mini-language to
handle presentation logic.

IMHO this is the funniest (worst) part of all this 'templating'
buss :)
It reminds me the good old slogan: "Have you invented your own GUI
library yet?"
The meme "thou shall not mix domain logic with presentation" is very
often misunderstood as "you must not have anything else than html in
templates", which is just plain non-sense. Even declarative templating
systems (cf Has's post) require some special (ie: non standard) stuff to
work.
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?
Bingo.

Then what is so *good* about it, why embedding HTML into Python is not
good?
Because _typically_ a web template consists of mostly HTML, with
relatively little presentational logic and (ideally) no business
logic. Now, if all one wants to do is a quick and dirty way to, say,
view a log file in the browser, a separate template is probably an
overkill; there's nothing wrong with something like "for line in
logfile: print cgi.escape(line .strip()) + '<BR>'". It's a matter of
relative frequencies which language is the embedded one.

George
Jun 30 '08 #7
On 30 juin, 19:19, Mike <ter...@gmail.c omwrote:
On Jun 30, 10:57 am, Bruno Desthuilliers <bruno.

42.desthuilli.. .@websiteburo.i nvalidwrote:
Some (if not most) templating systems use their own mini-language to
handle presentation logic.

IMHO this is the funniest (worst) part of all this 'templating'
buss :)
It reminds me the good old slogan: "Have you invented your own GUI
library yet?"
Yeps, there's something true here. FWIW, my favorite templating system
so for is still Mako, for it doesn't try to reinvent yet another
language - just uses Python as both the target runtime and the
scripting language.

(snip)
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?
Bingo.

Then what is so *good* about it, why embedding HTML into Python is not
good?
Who said embedding HTML in Python was bad ? Did you _carefully_ read
John's question ?-)

wrt/ what's so good about it: web designers are usually better at
working with this approach (whatever scripting language embedded in
html) than they are writing Python code - either as plain strings or
using a more declarative syntax like the one provided by Stan or
equivalent html generators. But nothing prevents you from using
Mako's internals directly if you find it easier and more
maintainable !-)

Jun 30 '08 #8
On Jun 30, 1:41 pm, George Sakkis <george.sak...@ gmail.comwrote:
>
Because _typically_ a web template consists of mostly HTML, with
relatively little presentational logic and (ideally) no business
logic. Now, if all one wants to do is a quick and dirty way to, say,
view a log file in the browser, a separate template is probably an
The keyword here is "(ideally)" . These _typical_ cases are pretty much
restricted to a helloworld-like examples or to a pure men log file
browser ;). Real application templates quickly became complicated and
require full blown scripting engine. Zope/Plone/Trac templates are
good examples of this.
... It's a matter of
relative frequencies which language is the embedded one.
Take a look at, say, http://trac.edgewall.org/browser/trunk/trac/templates
It is not obvious what relative frequency is higher. For other systems
the
situation is similar I believe.

So there should be something else that justifies this multitude of
template
systems. Unfortunately (for me :-) I couldn't find reasonable enough
explanation for this phenomena, except for the fact that it is a fun
to
write template engines ;). Probably not this time either.

Regards,
Mikhail

+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++
+++++
Q: What one would get after crossing two snakes and two hedgehogs?
A: Two meters of a barbed wire.
Jun 30 '08 #9
On Jun 30, 1:49*pm, "bruno.desthuil li...@gmail.com "
<bruno.desthuil li...@gmail.com wrote:
>
Then what is so *good* about it, why embedding HTML into Python is not
good?

Who said embedding HTML in Python was bad ? Did you _carefully_ read
John's question ?-)
I should have say "why embedding HTML into Python is not good
enough?" ;=)
wrt/ what's so good about it: web designers are usually better at
working with this approach (whatever scripting language embedded in
html) than they are writing Python code - either as plain strings or
using a more declarative syntax like the one provided by Stan or
I keep reading this argument that some mythical 'web designers' are
usually
better at working with this abracadabra (TAL etc.). BTW, most of the
times
it is used by programmers :). Sorry, I can't believe it. Sure there
are some
people that enjoy reading Perl or JCL, but all of them? IMHO if 'web
designer'
is able to separate HTML syntax from 'embedded language' syntax, then
he
is perfectly able to understand clear and simple Python code.
equivalent html generators. *But nothing prevents you from using
Mako's internals directly if you find it easier and more
maintainable !-)
Yea, that is a perfect and universal advise - use whatever fits you
best!;:=}

Jun 30 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2218
by: Edward Principe | last post by:
I'm working on an OpenSource project, and I'm looking for a web designer to write and administer the web site associated with the project. The project is a free (no money involved) project, and there's no money involved, but it will be a great experience if anybody is interested in being the web master of the project. The project is a RPG (Role Playing Game) that has a religious theme to it. The user must search out a bible for an...
1
1442
by: Martman | last post by:
Can someone point me to a good resource explaining how and why to use templates in php. I am new to php and wondering if these so called templates are just include files or what. And I have read several things about libraries in php but some of the applications I see are using includeonce files. Please don't tell me these are the same as libraries. I would consider libraries an application global resource that does not need to be...
6
1697
by: WebRod | last post by:
Hi, i want to rewrite my website to separate the php script from the HTML code. Therefore a web designer can update the design of the website without any knowledge in PHP. I read a lot of information about several templates like PhpLib, FastTemplates, Smarty etc etc. Some do not have a specific language so you cannot do complex things.
20
2992
by: Griff | last post by:
Hi there I'm after some suggestions as to how one might best separate form and content in a normal run-of-the-mill web application. I'm sure whole bookshelves have been written on this, but I could use some pointers as to the most helpful roads to investigate. The situation I'd like to end up with is the ability to split web development work into two halves - programmers writing back-end logic, and web designers building the look and...
4
2257
by: Simon Harvey | last post by:
Hello Chaps, Me and a collegue have been talking about where the best place to put business logic is. I think that the best place is where Microsoft suggest - in a seperate business logic layer. The alternative is to have all the logic in with the business entity objects, thus eliminating the business logic layer. The reason that I prefer the seperate layer is because I think its more
1
1091
by: Greg | last post by:
Hi, I am about to develop a simple Content Management system – main purpose would be posting articles. I am trying to find some ideas/ sample architecture showing how to separate application logic and content from its presentation. I would like to use some kind of predefined templates (only developer can cerate new templates); each template would be composed of certain controls and in would have some specific layout. The default.aspx...
1
2253
by: archady | last post by:
hi I have a script that enables separate content boxes to open or close but I need an option to have a link that opens or closes all the boxes at once. Here is the single script: function ShowHideMenu(menuID) { var theMenu = document.all("menu"+menuID)
10
2325
by: Frank van Wensveen | last post by:
Friend, coders, fellow wage slaves, lend my your ears. I believe that in a perfect world the design of a website (or feature on a website) should be totally separated from its design and the data it serves up. I'd like some suggestions on good ways to do this, because in the real world it can be quite difficult. For example, if I'm rummaging around in a MySQL database, the table structure and the code that generates the SQL requests...
0
178
by: dbpokorny | last post by:
On Jun 27, 9:09 am, "John Salerno" <johnj...@NOSPAMgmail.comwrote: This is a little anecdote about "separation of presentation, content, and logic." I used to work in a web application development environment that resembled Visual basic. The application presented its data through a java applet, and the server was written in lisp. If you were able to avoid the bugs (a bit like the fire swamps from The Princess Bride) then you could be...
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9786
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9568
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5794
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5983
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.