If you're happy with the current templates, then you don't really need to look at this documentation. Most people like to customise them a little at least, though, so this document describes how to do it.
The first thing you should do is go and look at the templates that
come with Vellum. Go on, do that now. They're in the
templates directory under your
directory. I'll wait here until you've done it.
OK, looking at that, you'll have had one of two reactions:
Vellum templates are Python embedded in HTML, in a Microsoft ASP sort of a way. This is not the place to teach you Python. If you're unsure of the language, then you'll find lots of information at the Python language website, and an excellent tutorial at Dive Into Python.
You embed a Python statement between <% and %> markers. That statement will be processed at that point when the template is rebuilt. Note that you can add HTML in the middle of loops and so on, so to print a list of numbers, you might do:
<h1>My list of numbers</h1> <% for num in range(5): %> The number is: <strong><% print num %><br> <% end %>You can also use
<%=expr%>as a shorthand for
<% print expr %>, where expr could be a variable or an expression; anything that would work with the
If you know Python, then you might have noticed something odd about
those templates: the word
end appears all over the place.
This is because, as you already know, Python does blocking by
indentation: you indent the contents of a loop and then stop indenting
when you reach the end of the loop code. This is exceedingly awkward
when your Python is embedded in HTML, because HTML is traditionally
indented for readability. So, as a compromise, Vellum insists that you
terminate loops with an
end statement, and indentation is
not required. Loops begin with a line that ends with a colon, and they
end with a line with
end alone on it. You can still indent
for readability, though. So the following Python code:
for i in range(5): for j in range(i,0,-1): print (i,j)becomes
for i in range(5): for j in range(i,0,-1): print (i,j) end endin a Vellum template.
Each Vellum template gets a few variables in its namespace which you don't have to gather yourself.
entries— a list of all entries that should be displayed in this template
blog— the blog containing those entries
entry— for individual templates (i.e., those which display only one entry), this is that entry
time— the Python time module (so you don't have to import it yourself)
blogvariable is actually a
vellum.Blogobject, so you can use any of that object's methods. Similarly,
entriesis a list of