Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 2 and Version 3 of DummyTemplate


Ignore:
Timestamp:
06/24/07 18:29:07 (12 years ago)
Author:
Chris Arndt
Comment:

migration notice

Legend:

Unmodified
Added
Removed
Modified
  • DummyTemplate

    v2 v3  
    1 This is a clever idea I had that maybe someone else could find usefull 
    2  
    3 I'll like to thank David Stanek from the Kid discuss list that help me out, when my call to locals() recurse to infinity  
    4  
    5 So I wanted a kid template that will display any variable that I send to it, so later on a designer or myself will replace it with the real template. 
    6  
    7 so here it is. 
    81{{{ 
    9 #!xml 
    10 <?python 
    11 def template_locals(template): 
    12    for name, value in template.__dict__.iteritems(): 
    13         if not name.startswith('_') and not name.startswith('tg') and not name is "std": 
    14             yield name, repr(value) 
    15 ?> 
    16 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    17    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    18 <html xmlns="http://www.w3.org/1999/xhtml" 
    19 xmlns:py="http://purl.org/kid/ns#"> 
    20     <head> 
    21         <title>Welcome to TurboGears</title> 
    22     </head> 
    23     <body> 
    24         <li py:for="var,val in template_locals(self)"> 
    25            <span>${var} = ${val}</span> 
    26         </li> 
    27     </body> 
    28 </html> 
     2#!rst 
     3.. note:: This page has been migrated to http://docs.turbogears.org/1.0/DummyTemplate. 
    294}}} 
    30  
    31 please note that the template_locals function maybe filter out whatever you like all that needs to be done is add more lines to that if. 
    32  
    33 peace 
    34  
    35 ---- 
    36  
    37 Just a small note. You shouldn't do identity tests on strings, its only the fact that small strings are (by convention) cached, that allows an `is` test to succeed in this case. So `and not name is "std"` should be `and name != "std"`. (any literal string over a certain number of characters will generate a new object every time, with my version of python 2.4.1 its 9 characters) 
    38  
    39 -- Sean Jamieson