Changeset 2917

Show
Ignore:
Timestamp:
08/11/08 20:58:59 (4 months ago)
Author:
bchoate
Message:

Updated POD docs for Var tag. BugId:80856

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-42/lib/MT/Template/ContextHandlers.pm

    r2872 r2917  
    32333233of expressions. The typical case is a simple variable name: 
    32343234 
    3235     <mt:Var name="foo"
     3235    <$mt:Var name="foo"$
    32363236 
    32373237Template variables may be arrays, or hash variables, in which case you 
     
    32413241This selects the second element from the 'foo' array template variable: 
    32423242 
    3243     <mt:Var name="foo[1]"
     3243    <$mt:Var name="foo[1]"$
    32443244 
    32453245This selects the 'bar' element from the 'foo' hash template variable: 
    32463246 
    3247     <mt:Var name="foo{bar}"
     3247    <$mt:Var name="foo{bar}"$
    32483248 
    32493249Sometimes you want to obtain the value of a function that is applied 
     
    32513251number of elements in the 'foo' array: 
    32523252 
    3253     <mt:Var name="count(foo)"> 
     3253    <$mt:Var name="count(foo)"$> 
     3254 
     3255Excluding the punctuation required in the examples above, the 'name' 
     3256attribute value should contain only alphanumeric characters and, 
     3257optionally, underscores. 
     3258 
     3259=item * value 
     3260 
     3261In the simplest case, this attribute triggers I<assignment> of the 
     3262specified value to the variable. 
     3263 
     3264    <$mt:Var name="little_pig_count" value="3"$>          # Stores 3 
     3265 
     3266However, if provided with the 'op' attribute (see below), the value becomes 
     3267the operand for the specified mathematical operation and no assignment takes 
     3268place. 
     3269 
     3270The 'value' attribute can contain anything other than a double quote. If you 
     3271need to use a double quote or the value is very long, you may want to use 
     3272the L<SetVarBlock> tag or the L<setvar> global modifier instead. 
    32543273 
    32553274=item * op 
    32563275 
    3257 Along with the 'value' attribute, this allows the application of 
    3258 a number of mathematical operators (see the L<If> tag for which 
    3259 are supported). 
    3260  
    3261 =item * value 
    3262  
    3263 If provided with the 'op' attribute, provides the operand for the 
    3264 specified mathematical operation. 
    3265  
    3266 If provided without the 'op' attribute, this causes the variable 
    3267 to be I<assigned> the value specified. In this way, this tag 
    3268 is useful for setting variables as well. 
     3276Used along with the 'value' attribute to perform a number of mathematical 
     3277operations on the value of the variable.  When used in this way, the stored 
     3278value of the variable doesn't change but instead gets transformed in the 
     3279process of being output. 
     3280 
     3281    <$mt:Var name="little_pig_count">                     # Displays 3 
     3282    <$mt:Var name="little_pig_count" value="1" op="sub"$> # Displays 2 
     3283    <$mt:Var name="little_pig_count" value="2" op="sub"$> # Displays 1 
     3284    <$mt:Var name="little_pig_count" value="3" op="sub"$> # Displays 0 
     3285 
     3286See the L<If> tag for the list of supported operators. 
     3287 
     3288=item * prepend 
     3289 
     3290When used in conjuction with the 'value' attribute to store a value, this 
     3291attribute acts as a flag (i.e. 'prepend="1"') to indicate that the new value 
     3292should be added to the front of any existing value instead of replacing it. 
     3293 
     3294    <$mt:Var name="greeting" value="World"$> 
     3295    <$mt:Var name="greeting" value="Hello " prepend="1"$> 
     3296    <$mt:Var name="greeting"$>  # Displays: Hello World 
     3297 
     3298=item * append 
     3299 
     3300When used in conjuction with the 'value' attribute to store a value, this 
     3301attribute acts as a flag (i.e. 'append="1"') to indicate that the new value 
     3302should be added to the back of any existing value instead of replacing it. 
     3303 
     3304    <$mt:Var name="greeting" value="Hello"$> 
     3305    <$mt:Var name="greeting" value=" World" append="1"$> 
     3306    <$mt:Var name="greeting"$>  # Displays: Hello World 
    32693307 
    32703308=item * function 
     
    32743312=over 4 
    32753313 
     3314=item * push 
     3315 
     3316Adds the element to the end of the array (becomes the last element). 
     3317 
    32763318=item * pop 
    32773319 
    3278 Takes an element from the end of the array (last element). 
     3320Removes an element from the end of the array (last element) and 
     3321outputs it. 
     3322 
     3323=item * unshift 
     3324 
     3325Adds the element to the front of the array (index 0). 
    32793326 
    32803327=item * shift 
     
    33093356=item * key 
    33103357 
    3311 Identifies a key of a hash template variable. 
     3358Identifies a value stored for the key of a hash template variable. 
    33123359 
    33133360=item * default 
    33143361 
    3315 If the variable is undefined or empty, this value will be output instead. 
     3362If the variable is undefined or empty, this value will be output 
     3363instead. Use of the 'default' and 'setvar' attributes together make 
     3364for an excellent way to conditionally initialize variables. The 
     3365following sets the "max_pages" variable to 10 if and only if it does 
     3366not yet have a value. 
     3367 
     3368    <mt:var name="max_pages" default="10" setvar="max_pages">  
    33163369 
    33173370=item * to_json