HTML formatting overlooked
Hey everyone, I'm trying to take advantage of the Random Content HOWTO (http://www.zope.org:18200/Documentation/How-To/RandomContent) to generate random quotes from famous scientists. I followed the directions carefully, but apparently I screwed up somewhere. Here's what I did. 1. I created a new folder just under / called 'quotes' 2. I filled /quotes with three DTML Methods--each one contained one quote. Here's an example: <p><i>The most incomprehensible thing about the universe is that it is comprehensible.</i><br><br> Albert Einstein</p> That's the entire contents of the object. 3. In my index_html object (in a sub-folder), I put the following dtml (according to the directions): <td width="20%" rowspan=2><dtml-var expr="_.whrandom.choice(quotes.objectValues())"></td> Unfortunately, Zope renders the contents of the quote literally, replacing, for example, all the < with <. The result can be seen at http://206.131.108.122:8080/atlas/. Why does this happen? -Tim -- Timothy Wilson | "The faster you | Check out: Henry Sibley H.S. | go, the shorter | http://slashdot.org/ W. St. Paul, MN, USA | you are." | http://linux.com/ wilson@chem.umn.edu | -Einstein | http://www.mn-linux.org/
Tim Wilson wrote:
<td width="20%" rowspan=2><dtml-var expr="_.whrandom.choice(quotes.objectValues())"></td>
Unfortunately, Zope renders the contents of the quote literally, replacing, for example, all the < with <. The result can be seen at http://206.131.108.122:8080/atlas/.
The expression "_.whrandom.choice(quotes.objectValues())" correctly chooses an object at random from your quotes, but then fails to render it. You need to write something like "_.whrandom.choice(quotes.objectValues())(this(), REQUEST)" to complete the process.
On Sun, 22 Aug 1999, Evan Simpson wrote:
The expression "_.whrandom.choice(quotes.objectValues())" correctly chooses an object at random from your quotes, but then fails to render it. You need to write something like "_.whrandom.choice(quotes.objectValues())(this(), REQUEST)" to complete the process.
Your suggestion worked perfectly. Thanks. I understand the statement pretty well as it was originally written, but I don't see what the purpose of the added '(this(),REQUEST)' is (other than to make my page work correctly :-). Could someone explain this. -Tim -- Timothy Wilson | "The faster you | Check out: Henry Sibley H.S. | go, the shorter | http://slashdot.org/ W. St. Paul, MN, USA | you are." | http://linux.com/ wilson@chem.umn.edu | -Einstein | http://www.mn-linux.org/
Tim Wilson wrote:
Your suggestion worked perfectly. Thanks. I understand the statement pretty well as it was originally written, but I don't see what the purpose of the added '(this(),REQUEST)' is (other than to make my page work correctly :-). Could someone explain this.
<dtml-var ...> operates in two very different modes. In name mode (<dtml-var name="eric"> or just <dtml-var eric>) it fetches the named object and renders it in the default context (current object and request). In expression mode (<dtml-var expr="eric"> or just <dtml-var "eric">) it evaluates the expression and then tries to convert the value into a string if it isn't one already. You are using expression mode (you had to!), and your expression returned a DTML object. The string value of a DTML object is its raw source code, conveniently html-quoted so that your browser will show it correctly. In order to get the result you want, you have to *call* the DTML object, which you do by placing a list of parameters in parenthesis after it (eg. "eric()", "eric(lastname='idle')", etc.). You have to provide the context parameters which the 'name mode' of dtml-var normally provides, namely the current object 'this()' as the client and the current request 'REQUEST' as the namespace.
participants (2)
-
Evan Simpson -
Tim Wilson