Changeset 3448:199c07ee0ba6 in livinglogic.python.xist

Show
Ignore:
Timestamp:
07/04/08 14:59:52 (11 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Update the UL4 howto to the new parameter passing method.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/UL4.rst

    r3441 r3448  
    4343    tmpl = ul4c.compile(code) 
    4444 
    45     print tmpl.renders([u"Python", u"Java", u"PHP"]) 
    46  
    47 The method :meth:`Template.renders` gets passed the data object (which is 
    48 available in the template code under the name ``data``) and returns the rendered 
    49 string. 
    50  
    51  
    52 Data objects 
    53 ============ 
    54  
    55 The template requires a data object for rendering the final output. 
    56 What :mod:`ll.ul4c` supports in this data object is very similar to what JSON_ 
    57 supports. 
    58  
    59     .. _JSON: http://www.json.org/ 
    60  
    61 Supported types are: 
     45    print tmpl.renders(data=[u"Python", u"Java", u"PHP"]) 
     46 
     47The variables that should be available to the template code can be passed to the 
     48method :meth:`Template.renders` as keyword arguments. :meth:`renders` returns 
     49the final rendered output as a string. Alternatively the method :meth:`render` 
     50can be used, which is a generator and returns the output piecewise. 
     51 
     52 
     53Supported data types 
     54==================== 
     55 
     56The following object types can be passed as variables to be used by the template 
     57code: 
    6258 
    6359    *   strings 
     
    7066    *   dictionaries 
    7167 
     68This is similar to what JSON_ supports (except for date objects). 
     69 
     70    .. _JSON: http://www.json.org/ 
     71 
    7272Note that depending on the implementation language of the renderer additional 
    7373types might be supported, e.g. a Python renderer will probably support tuples 
     
    7777loop). 
    7878 
    79 The data object itself will be available inside the template code under the name 
    80 ``data``. 
    81  
    82 Constants of these types can be created for all types. Most constants look 
    83 similar to the related Python constant. 
     79Objects the these types can either be passed to the template in the call to the 
     80render function, or the template can create objects of thoses types itself. The 
     81syntax for creating such a constant is very similar to Python's syntax. 
    8482 
    8583