[Zope] zpt wackyness

dman dman@dman.ddts.net
Tue, 30 Apr 2002 18:40:30 -0500


--+pHx0qQiF2pBVqBT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Apr 30, 2002 at 01:06:12PM -0700, Russell Uman wrote:
|=20
| i have a main page template: index_html
| i have a number of content templates that i would like to include
| into my main page. the title property is set for each object:
| content_1, title =3D "number one"
| content_2, title =3D "number two"
| content_3, title =3D "number three"
|=20
| i'm trying to dynamically choose which content object to display
| based on a request variable.
|=20
| here is what i have in index_html:
|=20
| <HTML tal:define=3D"page request/page | string:content_1">
| <span tal:replace=3D"python:container[page].title">title</span>
| <span tal:replace=3D"structure python:container[page]">body</span>
|=20
| this is what i see if i browse to index_html?page=3Dcontent_2
|=20
| number one
| <ZopePageTemplate instance at 8960bf0>

This is the repr() of the object.

| so the title is working! but the body is not.

It works, it's just not what you really meant to ask for :-).

| how can i get zope to include the contents of the object? is there a
| better way to translate a string into an object? if i make a
| call to tal:replace=3D"container/content_1" i have no problems - i
| just can't figure out how to do this dynamically...

<span tal:replace=3D"structure python:container[page]()">body</span>
                                                   ^^
                                                   ^^

I think it would be clearer if you made index_html a Python Script
instead.  It's what I'm doing with a site whose index needs to be
dynamically created based on who the user is and the contents of some
SQL dbs.


# Script(Python)

page REQUEST.get( 'page' , None ) :
if not page :
    page =3D 'content_1'

print container[page].title
print container[page]()

return printed


HTH,
-D

--=20

Pride only breeds quarrels,
but wisdom is found in those who take advice.
        Proverbs 13:10
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--+pHx0qQiF2pBVqBT
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjzPK24ACgkQO8l8XBKTpRRroACfe5luxTem8Oir5M38e1NK0rzU
MwUAn2Gke0PlsIyWgnS9Bq2d8RLT88v3
=R9xM
-----END PGP SIGNATURE-----

--+pHx0qQiF2pBVqBT--