NAME

Taco::Generic.pm - Generic Taco template functions

SYNOPSIS

These are generic functions that any Taco template may want to have available to it.

[[&query]]
[[&parse]]
[[&set]]
[[&if]]
[[&mark_me]]

DESCRIPTION

The general syntax for any of these functions is:

[[&name(arg1=val1 arg2='value two' ...)]
  or
[[&name arg1=val1 arg2=[[&name2 arg="value two" ]] ...]
  or
[[ &name ]]

Whitespace is optional at the beginning and end of the tag. A tag may be spread across several lines, which is useful if you've got lots of arguments you're passing to the function. See the documentation for Taco::Template for more information about the syntax. If you really want the juicy details you can look at the file t/docs/syntax.taco in the distribution package - it has lots of valid syntaxes for function calls.

  • [[&query(trailing=&)]]

    This function will return the query string (verbatim). The value of the trailing parameter will be appended if the query string exists (is not the empty string), which is useful in situations like this:

    <a href=page.taco?[[&query(trailing=&)]]flavor=cheese>Cheese City</a>

    If there's a query string (for example, "key=value"), this will appear as:

    <a href=page.taco?key=value&flavor=cheese>Cheese City</a>

    Otherwise it will appear as:

    <a href=page.taco?flavor=cheese>Cheese City</a>

    The only localized parameter is trailing.

  • [[&parse(parse_template=whatever)]]

    This will parse a template and insert its output here. If you specify the parse_template parameter, it will look for the named template in the template directories. In this way, it is similar to a server-side include.

    You can also use [[&parse(parse_text="verbatim text")]], though this is rarely useful.

    Taco will use the value of the TemplatePath attribute in the Taco::ServiceRegistry to look for your templates. See also Taco::ServiceRegistry.

    Localized parameters are parse_template and parse_text.

  • [[&set(name=flavor value=raspberry)]]

    The above function call will set the "flavor" entry to "raspberry" in the 'set' layer of the global parameter table. It will not output anything.

    Localized parameters are name and value.

    For more information about parameter tables, see Taco::Arg(3).

  • [[&if(condition='$var eq "hello"' true_text='it is hello' false_template=no_match)]]

    Use this function to write a conditional statement and output some text or a template based on the result. The condition can be any Perl expression that will compile under Safe.pm's ":base_core" option. This means that you're restricted to a small subset of Perl expressions, so check the error log if your template blows up - it might have an unallowable Perl expression in it. Furthermore, the condition parameter must be present in the function call itself, so you can't put ...&condition=1&field=... in the query string.

    Using the Safe.pm module gives some protection against web users changing the query string and doing something very bad to your system.

    The true_text and true_template parameters specify what should be output if the condition evaluates to true. You can use the special variable $result in your text (or template) to get the actual result of the evaluated condition.

    Likewise, the false_text and false_template parameters specify what should be output if the condition evaluates to false. $result is still available, though it's probably not very interesting.

    Localized parameters are condition, true_text, true_template, false_text, and false_template.

SEE ALSO

Taco(3), Taco::Template(3), Taco::Module(3)

TO DO

It would be nice to have an [[&elsif]] tag or some similar idea.

AUTHOR

Ken Williams (ken@forum.swarthmore.edu)

Copyright (c) 1998 Swarthmore College. All rights reserved.