EVO template files
EVO template files are found in the evo folders, and their names end in .evo. Template file names are typically of the form: Classname_methodname.evo.Master evo templates are in base/evo, while each app can add templates or override base templates in its own code/evo folder. Beware when overriding base templates, as updates to base may change these templates in ways that break your override templates.
EVO code files
EVO code is in 2 files:- evo.py : template parser
- html.py : python interface (defines a decorator @html for template-calling-functions
EVO parser
The evo parser has a 2-pass process:- evo to pyc (done only once per template, unless the template is altered)
- parse the source template into python
- compile the python into byte code
- cache it
- pyc to html (each call, i.e. on the fly)
- eval the python in the current context (i.e. req and self)
EVO calls
Template-calling-functions are defined within EVOKE-classes as @html methods, as follows:@html
def edit_form(self,req):
pass
This will call template evo/<Classname>.edit_form.evo, with parameters self and req. The method may contain some code, which will be run before the template is called. The method returns (implicitly - no return statement is used) the HTML output.
EVO wrappers
An EVO page may be wrapped in a wrapper, allowing a standard page header, footer, sidebars etc to be used on every page. The default wrapper is evo/wrapper.evo. This may be overridden as follows (in the @html method):req.wrapper="mywrapper.evo"
To use no wrapper: req.wrapper=None
content.here
Wrappers use a special content item: content.here to indicate where the wrapped content is to be placed. This should be the only non-blank item on that line.EVO language and syntax
EVO syntax is pythonic. Indentation is used to delineate blocks of code, and logic code syntax is almost identical to python.tags
tagname: <content> , <attribute>, <attribute>:: where content can be EITHER inline (if text expression only) OR block (text expression, tags, logic), and there may be any number of attributes, each in the form attribute=value.
<content>
e.g.:
div: id="maindiv": this shows how tags can contain tags, and that attributes are optional
div:self.name, cls='name'
br:
a: "click here to view", href=self.url(), title='view %s' % self.name
conditions
if <expr> :: the blocks must be on separate lines, unlike in python
,block>
elif <expr>:
<block>
else:
<block>
looping
for <var> in <sequence or iterator>:expressions
expressions are python code, and will be evaluated directly by eval(). It is advisable, though generally unnecessary, to enclose complex expressions in parentheses: ( ).comments
# this is a comment : the # must be the first non-blank character on the line (unlike in python)variables
myvar = <expression>: creates a local variable with scope limited to the current block (and chilld blocks)
macros
mymacro =: these allow repetitive code to be factored
<block>
sub-templates
templatename or object.templatename : any line starting with a template name (including the .evo suffix) will be substituted by the results of calling that template. The req and lib objects are passed to the subtemplate, and the given object is passed as self - where no object is given, self is passed.parameters
The following objects are available within EVO code:- self : the current data object (parameter)
- req : the current browser request (parameter)
- lib : standard library routines, per base/lib
syntax error handling
The parser looks for some sytnax errors, and reports these in the log. However, other syntax errors will not be identified explicitly but will cause other application errors.Typical syntax errors include:
- indent and dedent errors (a la python)
- no : after if, elif, else, etc.
- tag has inline content AND block content
- commas omitted between tag parameters (attributes)
tag reference
HTML tags:
These tags are named identically to their HTML equivalents. Some tags have default attribute values, as indicated below:- a:
- b:
- body:
- br:
- button: type='submit'
- caption:
- cite:
- dd:
- dl:
- dt:
- div:
- fieldset:
- form: method='post'
- h1:
- h2:
- h3:
- h4:
- h5:
- h6:
- head:
- html:
- i:
- img:
- input: type='text',value=''
- label:
- legend:
- li:
- link:
- meta:
- noscript:
- ol:
- option:
- p:
- pre:
- script: type="text/javascript
- select:
- span:
- table:
- td:
- textarea:
- th:
- title:
- tr:
- ul:
special tags
These are compound tags:- buttonnorm:
- buttoncool:
- buttonbig:
attributes
Tag attributes are as per HTML, except for the following:- class becomes cls, as class is a reserved word in python
- for becomes for_id, as for is a reserved word in python
- http-equiv can be shortened to equiv