Defining Macros
You can define your own macros by creating a <name>.inc or <name>.macro file. The .inc will be copied character for character to you page, and should be used for instance to create standard headers. The .macro is more intereting: here you can put in some python code. Whatever the code finally puts into the variable called output will be placed into the page.
In the macro itself you have these variables at your disposal:
-
output
This variable should contain your macro output as a string at the end
of the code.
-
arguments
Array containing any arguments that were passed to the macro (as
strings). It is prudent to check if these arguments are present. The
arguments variable will contain an emply list if no arguments were
passed.
-
macro_name
Contains the name of the macro.
-
macro_source
Contains the python source code of this macro
-
page
This variable contains the Page class object that represents the page
in which the macro was found. The page class has the following variables and methods:
-
input_line
Contains the input line from the .page file where this macro was read.
-
page variables
- options The global variable containing .setup file options. You can read these out with
- get_option(options, "option_name") for single options
- get_options(options, "option_name") for plural options (ie. lists)
-
get_option_dir(options, "option_name")
for options that contain files or directories. These will be made
absolute (for the system you run clcms on, not for the website) if
they do not start with a /
-
name
Contains the title of the current page.
-
parent
The parent page of this page
-
input_directory
Contains the location of the content input directory (i.e. the source
directory of the current page).
-
contents
Contains a list of Content class object, which represent content
files for the current page.
-
show_submenu
True if the submenu should be generated.
-
macros
Contains all macros
- page methods
-
getPageDepth()
The current page (directory) depth.
-
getRootPage()
Returns the root page of the current site (the page that has no parent)
-
getBackDir()
Returns a the relative path to the root page from this page (for
instance ../../)
-
findPageDate()
Returns the timestamp of the last modified content file for this
page, or of the page directory itself if that date is later.
-
findPageByID(id)
If this page has a child with the given id (or one of it's children
does) that page is returned.
-
getNextPage(return_children)
Returns the page following this one in the site. If the
return_children argument is true, it also checks pages below this
one. Returns None if this is the last page
-
getPreviousPage(return_children)
Returns the page following this one in the site. If the
return_children argument is true, it also checks children pages.
Returns None if this is the last page