6.10. Including other documents or scripts
Inside a script you can ask Karrigell to include the content of another static file or the output of another script by theInclude(url)
function, where url is the url of the file or script
(you can use aliases as for ordinary files)
This is useful if you want to build a set of pages with components which will be present in each page (for instance a header and/or a footer). Your script will be built this way :
Include("authenticationTest.py") # a script testing user authentication Include("header.htm") # a static file with a title, style sheet etc (... your script body ...) Include("footer.py") # a script which will print current date for instance
At runtime, Karrigell will raise a RecursionError in case of loops (scripts that include themselves, or script 1 includes script 2 which includes script 1)
6.10.1 Namespace
An included script is run in the same namespace as the script which "calls" it, including the variables defined in this script : if the caller script is
name="Brian" print "The life of " Include("whoseName.py")
and whoseName.py is
print name
you'll see that the name
variable is available in the included
script
6.10.2 Passing parameters
It can be useful to pass parameters to an included script : see for instance the menu script in the personal portal demo. This script takes as parameters a list of menu items and the list of matching urlsIt will be included this way :
Labels=[...] Urls=[...] Include("k_menu.hip", labels=Labels, urls=Urls, targetUrl="index.pih")
Parameters can also be passed in the query string appended to the script
url : with Include("/mypath/aScript.pih?data=dummy")
the variable
data
will be available in the namespace of aScript.pih