ad_page_contract_filter (public)
ad_page_contract_filter [ -deprecated ] [ -type type ] \ [ -priority priority ] name proc_args doc_string body
Defined in packages/acs-tcl/tcl/tcl-documentation-procs.tcl
Declare a filter to be available for use in ad_page_contract.
Here's an example of how to declare a filter:
ad_page_contract_filter integer { name value } { Checks whether the value is a valid integer, and removes any leading zeros so as not to confuse Tcl into thinking it's octal } { if { ![regexp {^[0-9]+$} $value] } { ad_complain [_ acs-tcl.lt_Value_is_not_an_integ] return 0 } set value [util::trim_leading_zeros $value] return 1 }After the filter has been declared, it can be used as a flag inad_page_contract
, e.g.ad_page_contract { foo:integer } {}Note that there's only one global namespace for names. At some point, we might add package-local filters, but we don't have it yet.The filter proc must return either 1 if it accepts the value or 0 if it rejects it. Any problem with the value is reported using
ad_complain
(see documentation for this). Note: Any modifications you make to value from inside your code block will modify the actual value being set in the page.There are two types of filters. They differ in scope for variables that are multiple or array. The standard type of filter (filter classic) is invoked on each individual value before it's being put into the list or the array. A post filter is invoked after all values have been collected, and is invoked on the list or array as a whole.
- Switches:
- -deprecated (optional, boolean)
- used to flag a filter as deprecated
- -type (optional, defaults to
"filter"
)- The type of filter; i.e.
filter
orpost
. Default isfilter
.- -priority (optional, defaults to
"1000"
)- Parameters:
- name (required)
- The name of the flag as used in
ad_page_contract
- proc_args (required)
- the arguments to your filter. The filter must take three arguments,
name
,value
, andparameters
, although you can name them any way you want. The first will be set to the name of the variable, the second will be upvar'd to the value, so that any change you make to the value will be reflected in the value ultimately being set in the page's environment, and the third is a list of arguments to the filter. This third argument can have multiple parameters split by|
with no spaces or any other characters. Something likefoo:range(3|5)
- doc_string (required)
- Standard documentation-string. Tell other programmers what your filter does.
- body (required)
- The body is a procedure body that performs the filtering. It'll automatically have one argument named
value
set, and it must either return the possibly transformed value, or throw an error. The error message will be displayed to the user.- Author:
- Lars Pind <lars@pinds.com>
- Created:
- 25 July 2000
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- page_contracts