spyce
         
home     documentation     download     Spyce logo


Documentation - Tags

Prev: 3.9 - Tags Up: 3.9 - Tags Next: 3.9.2 - Form

3.9.1. Core

The core tag library is aliased as "spy" by default.

This library contains various frequently-used tags: the parent tag, login tags, and some tags for generating lists and tables from Python iterators.

Parent Tag

  • <parent [src=url] [other parameters] />
    Specifies a parent template to apply to the current page, which is passed to the parent as child._body. Any extra parameters are also passed in the child dictionary. If src is not given, 'parent.spi' used if it exists in the current directory; otherwise, the default parent is used as specified in the config module.

    examples/hello-templated.spy
    <spy:parent title="Hello, world!" />
    
    [[-- Spyce can embed chunks of Python code, like this. --]]
    [[\
      import time
      t = time.ctime()
    ]]
    
    [[-- 
      pull the count from the GET variable.
      the int cast is necessary since request stores everything as a string 
    --]]
    [[ for i in range(int(request.get1('count', 2))):{ ]]
    <div>Hello, world!</div>
    [[ } ]]
    
    The time is now [[= t ]].
    
    Run this code
Login Tags
  • <login [validator=function name] />
    Generates a login form according to the template specified in your config file. If validator is not specified, the default validator from your config file is used. (validator may be the name of a function in a different Python module; just prefix it with the module name and Spyce will automaticall import it when necessary.)

    examples/login-optional.spy
    <html><body>
    
    <f:form>
      [[ if request.login_id():{ ]]
        You are logged in with user id [[= request.login_id() ]]
        <spy:logout />
      [[ } else: { ]]
        <spy:login />
        You are not logged in.  (You may login with username/password: spyce/spyce.)
      [[ } ]]
      
      <p>
      (Here is some content that is the same before and after login.)
    </f:form>
    
    </body></html>
    Run this code
  • <logout />
    Generates a logout button that will clear the cookie generated by login and login_required.

  • <login_required [validator=function name] />
    If a valid login cookie is not present, generates a login form according to the template specified in your config file, then halts execution of the current page.

    (You may log in to this example as user spyce, password spyce.)

    examples/login-required.spy
    <spy:parent title="Login example" />
    
    <f:form>
      <spy:login_required />
    
      You are logged in.
      <spy:logout />
    </f:form>
    
    Run this code
Convenience Tags

These tags are shortcuts for creatings lists and tables. As with the form tag library, any python iterator may be given as the data parameter. Also as with the form tags, any unrecognized parameters will be passed through to the generated HTML.

  • <ul data=expr] />
    Convenience tag for the common use of ul; equivalent to
        <ul>
        [[ for item in data:{ ]]
          <li>[[= item ]]</li>
        [[ } ]]
        </ul>
      
  • <ol data=expr] />
    Like ul, but for ordered lists.

  • <dl data=expr] />
    Convenience tag for the common use of dl; equivalent to
      <dl>
      [[ for term, desc in data:{ ]]
        <dt>[[= term ]]</dt>
        <dd>[[= desc ]]</dd>
      [[ } ]]
      </dl>
      
  • <table data=expr] />
    Convenience tag for the common use of table; equivalent to
      <table>
      [[ for row in data:{ ]]
        <tr>
        [[ for cell in row:{ ]]
          <td>[[= cell ]]</td>
        [[ } ]]
        </tr>
      [[ } ]]
      </table>
      

Prev: 3.9 - Tags Up: 3.9 - Tags Next: 3.9.2 - Form


Spyce logo
Python Server Pages
version 2.1.3
Spyce Powered SourceForge Logo