Using MySQL results for condition checking in ZPT
I have created a ZSQL method which expands the query results depending upon the variables supplied: SELECT <dtml-if "Category != '%' or fullSearch">Category, </dtml-if><dtml-if "Notes != '%' or fullSearch">Notes, </dtml-if><dtml-if "Language != '%' or fullSearch">Language, </dtml-if><dtml-if fullSearch>ISBN, UPC, Cost, Resale, Rate, Rent_Per, Keywords, </dtml-if>ItemID, Type, Name, Status FROM Movie_Records INNER JOIN Movie_Inv ON Movie_Records.MovieID = Movie_Inv.MovieID WHERE Status <=1 AND Name LIKE <dtml-sqlvar Name type="string"> AND Language LIKE <dtml-sqlvar Language type="string"> AND Category LIKE <dtml-sqlvar Category type="string"> AND Notes LIKE <dtml-sqlvar Notes type="string"> AND Keywords LIKE <dtml-sqlvar Keywords type="string"> ORDER BY Type, Language, Name ASC This works splendidly. My problem is displaying the results while dynamically formating the table. If the column has no results then I'd like to omit it. My TAL condition that I'm attempting to use is something like: For the Table Header: <span tal:condition="result/Category"> <th>Category</th> </span> And the Body: <span tal:condition="result/Category"> <td><span tal:replace="result/Category">Category goes here</span></td> </span> This seems very simplistic to me, but Zope doesn't agree with the way I'm access the variables. I think that my understanding of "result/Category" and Zope variables is fundamentally flawed, but I can't seem to find any clear documentation on this aspect of Zope. Can someone help me get a clue? -- Ben M. Thomas <ben@smallercircle.com>
Ben M. Thomas wrote: [...]
My TAL condition that I'm attempting to use is something like:
For the Table Header: <span tal:condition="result/Category"> <th>Category</th> </span>
And the Body: <span tal:condition="result/Category"> <td><span tal:replace="result/Category">Category goes here</span></td> </span>
If I understand correctly, you're getting an error when Category is not an attribute of result. I think you are looking for: <th tal:condition="exists:result/Category">Category</th> and <td tal:condition="exists:result/Category" tal:content="result/Category">Category goes here</td> (no need for span tags) Look for "Alternate Paths" and "Exists Expressions" in chp. 9 of the Zope Book HTH, Fernando
participants (2)
-
Ben M. Thomas -
Fernando Martins