home | news | documentation | source | downloads | discussion | projects | license  

 
Documentation
 
   Overview
   Why Clearsilver?
   Clearsilver Basics
     HDF Dataset
     Template Syntax
       Expressions
       Macros
       Functions
     CGI Kit
       Config Vars
     FAQ
   API Reference
     API Concepts
     C API
     Python API
       Introduction
     Perl API
     Java API
   Tools
     odb.py
   Comparison with PHP, ASP, JSP
   Comparison with XML/XSLT


 
    
Example #1, using the CGI kit with clearsilver templating:

  import neo_cgi
 
  # send neo_cgi handler through the python stdin/stdout/environ
  # calls

  neo_cgi.cgiWrap(context.stdin, context.stdout, context.environ)

  # setup a random form handling option

  neo_cgi.IgnoreEmptyFormVars(1)

  # create a CGI handler context
  ncgi = neo_cgi.CGI() 

  # setup HDF loadpaths (relative from the current directory)
  ncgi.hdf.setValue("hdf.loadpaths.0","tmpl")

  # parse the form data (and post upload data)
  ncgi.parse()

  # read static HDF data into the HDF dataset

  ncgi.hdf.readFile("mytemplate.hdf")

  # process some query data (second argument is default value if missing)

  a_var = ncgi.hdf.getValue("Query.a_var","")
  a_cookie = ncgi.hdf.getValue("Cookie.a_cookie","")
  a_int_var = ncgi.hdf.getIntValue("Query.a_int_var,0)


  # put some data into the HDF dataset

  ncgi.hdf.setValue("CGI.Page.Title","My Webpage")
  ncgi.hdf.setValue("CGI.Page.Contents","This is the page contents")

  # use some utility functions

  ncgi.hdf.setValue("CGI.HDFDUMP",neo_cgi.htmlEscape(ncgi.hdf.dump()))

  # render the clearsilver template

  ncgi.display("mytemplate.cst") 


Example 2, using CS/HDF without using the Clearsilver CGI kit:

  import neo_cgi
  import neo_util  # you must import neo_cgi first...  
  import neo_cs    # you must import neo_cgi first...

  hdf = neo_util.HDF()  # create an HDF dataset
  hdf.setValue("hdf.loadpaths.0","/my/path")  # setup a load path
  hdf.readFile("my_file.hdf") # read some HDF data
  hdf.setValue("CGI.foo","bar")

  cs = neo_cs.CS(hdf)
  cs.parseStr("") # parse a string

  cs.parseFile("my_file.cst") # parse a file from disk
  print cs.render()

 
Copyright © 2020 Brandon Long, All rights reserved.