To define a tag that is catalog-specific, place UserTag directives in your catalog.cfg file. For server-wide tags, define them in minivend.cfg. Catalog-specific tags take precedence if both are defined -- in fact, you can override the base MiniVend tag set with them. The directive takes the form:
UserTag tagname property value
where tagname
is the name of the tag, property
is the attribute (described below), and value is the value of the property for that tagname.
The user tags can either be based on Perl subroutines or just be aliases for existing tags. Some quick examples are below.
An alias:
UserTag product_name Alias data products title
This will change [product_name 99-102]
into [data products title 99-102]
, which will output the title database field for product code 99-102
. Don't use this with [item-data ...]
and [item-field ...]
, as they are parsed separately. You can do [product-name [item-code]]
, though.
A simple subroutine:
UserTag company_name Routine sub { "Your company name" }
When you place a [company-name]
tag in a MiniVend page, the text
Your company name
will be substituted.
A subroutine with a passed text as an argument:
UserTag caps Routine sub { return "\U@_" } UserTag caps HasEndTag
The tag [caps]This text should be all upper case[/caps]
will become
THIS TEXT SHOULD BE ALL UPPER CASE
.
Here is a useful one you might wish to use:
UserTag quick_table HasEndTag UserTag quick_table Interpolate UserTag quick_table Order border UserTag quick_table Routine <<EOF sub { my ($border,$input) = @_; $border = " BORDER=$border" if $border; my $out = "<TABLE ALIGN=LEFT$border>"; my @rows = split /\n+/, $input; my ($left, $right); for(@rows) { $out .= '<TR><TD ALIGN=RIGHT VALIGN=TOP>'; ($left, $right) = split /\s*:\s*/, $_, 2; $out .= '<B>' unless $left =~ /</; $out .= $left; $out .= '</B>' unless $left =~ /</; $out .= '</TD><TD VALIGN=TOP>'; $out .= $right; $out .= '</TD></TR>'; $out .= "\n"; } $out .= '</TABLE>'; } EOF
Called with:
[quick-table border=2] Name: [value name] City: [value city][if value state], [value state][/if] [value country] [/quick_table]
The properties for UserTag are are:
undef
, interpolate
, and any other attributes you have set in the tag. Allows your tag routine
to take a hash reference with the important parameters. Example:
UserTag echo-params AddAttr UserTag echo-params Routine <<EOR sub { my($ref) = @_; my $out; for (sort keys %$ref) { # skip these meaningless parameters next if /^(undef|true|false)$/;
$out .= "$_="; $out .= '"'; $out .= $ref->{$_}; $out .= '"' $out .= "\n"; } return $out; } EOR
If you define the above UserTag and put put this on a MiniVend page
<PRE> [echo-params Param1=1 param2=2 param3=three] </PRE>
the resulting output will be:
interpolate="0" param1="1" param2="2" param3="three"
The interpolate
parameter is always present for every tag, and defines the behavior of
container text or output depending on the value of HasEndTag.
UserTag tagname Alias tag to insert
An Alias is the only property that does not require a Routine to process the tag.
UserTag tagname attrAlias alias attr
As an example, the standard MiniVend value tag takes a named attribute of name for the variable name, meaning that [value name=var]
will display the value of form field var
. If you put this line in catalog.cfg:
UserTag value attrAlias identifier name
then [value identifier=var]
will be an equivalent tag.
tag_loop_list
and tag_if
in lib/Vend/Interpolate.pm for an example of a nesting tag.
UserTag tagname CanNest
timed-build
and
mvasp
tags are the tags MiniVend defines to Gobble.
[/tag]
to encapsulate your text -- the text in between the beginning [tagname]
and ending [/tagname]
will be the last argument sent to the defined subroutine.
UserTag tagname HasEndTag
attribute
instead of an attribute=value
pair. It must be a recognized attribute in the tag definition, or there
will be big problems. Use this with caution!
UserTag tagname Implicit attribute value
If you want to set a standard include file to a fixed value by default, but
don't want to have to specify [include file="/long/path/to/file"]
every time, you can just put:
UserTag include Implicit file file=/long/path/to/file
and [include file]
will be the equivalent. You can still specify another value with [include file="/another/path/to/file"]
UserTag
will be re-parsed for more MiniVend tags. If it is a container, Interpolate
causes the contents of the tag to be parsed before the tag routine is run.
UserTag tagname Interpolate
UserTag tagname InvalidateCache
It does not override [tag flag build][/tag]
, though.
UserTag tagname Order param1 param2
[usertag argument]
instead of [usertag ARG=argument]
. If not defined, Routine is used, and MiniVend will usually do the right thing.
UserTag tagname ReplaceAttr htmltag attr
An example is the standard
HTML <
A
HREF=...> tag. If you want to use the MiniVend tag
[area pagename]
inside of it, then you would normally want to replace the
HREF attribute. So the equivalent to the following is
defined within MiniVend:
UserTag area ReplaceAttr a href
Causing this
<A MV="area pagename" HREF="a_test_page.html">
to become
<A HREF="http://yourserver/cgi/simple/pagename?X8sl2lly;;44">
when intepreted.
minivend.cfg
parameter AllowGlobal is set for the catalog.
UserTag tagname Routine sub { "your perl code here!" }
The routine may use a ``here'' document for readability:
UserTag tagname Routine <<EOF sub { my ($param1, $param2, $text) = @_; return "Parameter 1 is $param1, Parameter 2 is $param2"; } EOF
The usual here documents caveats apply.
Parameters defined with the Order property will be sent to the routine first, followed by any encapsulated text (HasEndTag is set).
Note that the UserTag facility, combined with AllowGlobal, allows the user to define tags just as powerful as the standard MiniVend tags. This is not recommended for the novice, though -- keep it simple. 8-)