For expressions, the expression is evaluated and the result is embedded
in the final HTML.
For statements and code blocks, all code is executed, and anything
printed to stdout is displayed in the HTML. Anything else does not affect the
HTML.
For example, the following Python expression will evaluate to '4':
<% 2+2 %>And this code will embed the text 'Hello, world!' in HTML:
<# print "Hello, world!" #>Of course, more complex code is possible... the sky is the limit. For multiple lines of code, make sure you have the indentation right, though.
From the code, you can access two important objects: blog and entry.
For a quick start, here are the attributes that are most important:
blog.title
The title of the weblog, obviously. Use this in your <title> tag, or just to display the title anywhere you want (page header, etc).blog.messages()
A very important method: it embeds the messages (entries) in the page. IOW, it's a way of saying "messages go here". Note that every message is wrapped in its own template; see the entry template for that.Other, less important attributes include:
Which entries are displayed on which page, depends on the situation and the type of page being generated. Your "start page" can display the N most recent entries, archive pages will display entries of certain dates, and for custom pages you can select any entry you want.
blog.current_page
The name (URL) of the current page. This is not a fully qualified URL with "http://" and all that, by the way; it's just a page name.blog.next_page, blog.previous_page
These are only used on archive pages. Use them to point to the next or previous page; this obviously doesn't make sense for single pages.blog.categories
A list of categories (as strings) that this weblog has.blog.archive_list()
Returns an archive list, in HTML. This is used to embed ready-to-go HTML that displays a list of archive files, separated by <br> tags.blog.filename
May go away or be moved in future versions, since it's too specific for my taste.
The name of the front page.blog.description
Maybe this name should change...
The description of the weblog, as entered by you in Kaa.blog.get_permalink(entry_id)
Generates a permalink for the given entry, using its entry id.
XXX Is this the same as entry.anchor? Should it be?
entry.title
Speaks for itself.entry.insert_date
The date/time you inserted the entry, represented as an ISO date string (YYYY-MM-DD HH:MM:SS). You can display this verbatim or use slicing to chop off unwanted parts, or even use your own function to process this date and make it into something more human-readable ("Wednesday 9 July", etc). The point is that this date representation is unambiguous, easy to store and use, and sortable.entry.modified_date
The date and time this entry was last modified.entry.blogentry_id
The id of the current entry, in the database table. The id is important since it's used in permalinks, etc. It can also be used for commenting systems (YACCS, Haloscan, etc).entry.anchor
A permalink to the current entry. Or rather, to the archived version of the current entry. (An entry on the start page doesn't have a permalink to itself, since that link isn't permanent at all... rather, it has a link to the entry in the archives.)entry.misc
This is a dictionary that can contain all kinds of data; currently it's not been used to its full extent by Kaa... yet. Currently implemented are:
- The categories key, which contains a list of category names (strings) associated with this entry.
- The visible key, which indicates whether the entry is visible or not. If not present, the entry is considered visible. ("Not visible" obviously means that the entry will not show up in any pages.)