[Zope] Quoting HTML

Passin, Tom tpassin@mitretek.org
Thu, 10 Oct 2002 23:25:12 -0400


Beno]

>I have the following Python Script (*not* External Script):
>=20
> import string
>=20
> size =3D string.atoi(size)/1280
> css =3D "<style type=3D'text/css'>"
> css +=3D ".headline { position: absolute; top: " +=20
> str(100*size) + "; left: "=20
> + str(150*size) + "; font-style: 800 " + str(40*size) + "px futura }"
> css +=3D ".belowHeadline { position: absolute; top: " +=20
> str(150*size) + ";=20
> left: " + str(250*size) + "; font-style: italic " +=20
> str(25*size) + "px=20
> verdana }"
> css +=3D "</style>"
> return css
>=20
>=20
> It isn't rendering properly because the brackets are being=20
> translated into=20
> ASCII. How do I prevent this?

Do not use Python to write markup.  Return a data structure to dtml and
use dtml to create the markup (or use zpt).

For example -

In script scaleSizes(size) :

real_size=3Dstring.atoi(size)/1280
values=3D{'top':str(100*real_size), 'left':str(150*real_size)}
return values

In a dtml page or method:

<dtml-let sizes=3D"scaleSizes(size)">
	<style type=3D'text/css'>
	.headline { position: absolute; top:<dtml-var "sizes['top']">;
		left:<dtml-var "sizes['left']">}
	</style>
</dtml-let>

In other words, let Python do what it is good at and let dtml or zpt do
what it is good at - which is rendering markup.  The result is a lot
more readable and maintainable.

Cheers,

Tom P