1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 1999-2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Content Stylesheet for Site -->
<!-- start the processing -->
<!-- ====================================================================== -->
<!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
<!-- Main Page Section -->
<!-- ====================================================================== -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="author" value="Velocity Documentation Team">
<meta name="email" value="jvanzyl@zenplex.com">
<meta name="author" value="John Castura">
<meta name="email" value="jcastura@apache.org">
<title>Velocity - VTL Reference Guide</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#525D76">
<table border="0" width="100%" cellspacing="0">
<!-- TOP IMAGE -->
<tr>
<td align="left">
<a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" border="0"/></a>
</td>
<td align="right">
<a href="http://jakarta.apache.org/velocity/"><img src="./images/logo.gif" alt="Velocity" border="0"/></a>
</td>
</tr>
</table>
<table border="0" width="100%" cellspacing="4">
<tr><td colspan="2">
<hr noshade="" size="1"/>
</td></tr>
<tr>
<!-- LEFT SIDE NAVIGATION -->
<td width="20%" valign="top" nowrap="true">
<!-- ============================================================ -->
<p><strong>About</strong></p>
<ul>
<li> <a href="./index.html">Overview</a>
</li>
<li> <a href="./getting-started.html">Getting Started</a>
</li>
<li> <a href="http://jakarta.apache.org/builds/jakarta-velocity/">Download</a>
</li>
<li> <a href="./install.html">Install</a>
</li>
<li> <a href="./design.html">Design</a>
</li>
<li> <a href="./contributors.html">Contributors</a>
</li>
<li> <a href="./changes.html">ChangeLog</a>
</li>
<li> <a href="./code-standards.html">Coding Standards</a>
</li>
<li> <a href="./license.html">License</a>
</li>
<li> <a href="./todo.html">TODO</a>
</li>
<li> <a href="http://issues.apache.org/bugzilla/enter_bug.cgi?product=Velocity">Report Issues</a>
</li>
</ul>
<p><strong>Community</strong></p>
<ul>
<li> <a href="./powered.html">Powered By Velocity</a>
</li>
<li> <a href="http://jakarta.apache.org/site/getinvolved.html">Get Involved</a>
</li>
<li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a>
</li>
<li> <a href="http://jakarta.apache.org/site/cvsindex.html">CVS Repositories</a>
</li>
</ul>
<p><strong>Docs</strong></p>
<ul>
<li> <a href="./user-guide.html">User's Guide (English)</a>
</li>
<li> <a href="./user-guide_fi.html">User's Guide (Finnish)</a>
</li>
<li> <a href="./user-guide_fr.html">User's Guide (French)</a>
</li>
<li> <a href="./user-guide_es.html">User's Guide (Spanish)</a>
</li>
<li> <a href="./developer-guide.html">Developer's Guide</a>
</li>
<li> <a href="./vtl-reference-guide.html">VTL Reference Guide</a>
</li>
<li> <a href="./specification.html">Specification</a>
</li>
<li> <a href="./api/index.html">Javadoc</a>
</li>
</ul>
<p><strong>Tools</strong></p>
<ul>
<li> <a href="./tools/index.html">Velocity Tools</a>
</li>
<li> <a href="./anakia.html">Anakia : XML->doc tool</a>
</li>
<li> <a href="./texen.html">Texen : text generation</a>
</li>
<li> <a href="./dvsl/index.html">DVSL : XML xformation</a>
</li>
<li> <a href="./veltag.html">Veltag : JSP taglib</a>
</li>
<li> <a href="./migration.html">Migration to Velocity</a>
</li>
<li> <a href="./devtools.html">Editors and IDEs</a>
</li>
</ul>
<p><strong>Comparisons</strong></p>
<ul>
<li> <a href="./ymtd/ymtd.html">YMTD</a>
</li>
<li> <a href="./differences.html">VM/WM Differences</a>
</li>
<li> <a href="./casestudy1.html">JSP vs. Velocity</a>
</li>
<li> <a href="./casestudy2.html">XMLC vs. Velocity</a>
</li>
</ul>
<p><strong>Site Translations</strong></p>
<ul>
<li> <a href="http://jakarta.apache.org/velocity/">English</a>
</li>
<li> <a href="http://www.ingrid.org/jajakarta/velocity/velocity-1.2-rc2/docs-ja/index.html">Japanese</a>
</li>
</ul>
</td>
<td width="80%" align="left" valign="top">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="About this Guide"><strong>About this Guide</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
This guide is the reference for the Velocity Template Language
(VTL). For more information, please also refer to the <a href="user-guide.html">Velocity User Guide</a>.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="References"><strong>References</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Variables"><strong>Variables</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Notation:
</p>
<p>
<strong>$</strong> [ <strong>!</strong> ][ <strong>{</strong> ][
<strong>a..z</strong>, <strong>A..Z</strong> ][ <strong>a..z</strong>,
<strong>A..Z</strong>, <strong>0..9</strong>, <strong>-</strong>,
<strong>_</strong> ][ <strong>}</strong> ]
</p>
<p>
Examples:
</p>
<ul>
<li>Normal notation: <variable>$mud-Slinger_9</variable></li>
<li>Silent notation: <variable>$!mud-Slinger_9</variable></li>
<li>Formal notation: <variable>${mud-Slinger_9}</variable></li>
</ul>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Properties"><strong>Properties</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Notation:
</p>
<p>
<strong>$</strong> [ <strong>{</strong> ][ <strong>a..z</strong>,
<strong>A..Z</strong> ][ <strong>a..z</strong>, <strong>A..Z</strong>,
<strong>0..9</strong>, <strong>-</strong>, <strong>_</strong> ]*
<strong>.</strong>[<strong>a..z</strong>, <strong>A..Z</strong> ][
<strong>a..z</strong>, <strong>A-Z</strong>, <strong>0..9</strong>,
<strong>-</strong>, <strong>_</strong> ]* [ <strong>}</strong> ]
</p>
<p>
Examples:
</p>
<ul>
<li>Regular Notation: $customer.Address</li>
<li>Formal Notation: ${purchase.Total}</li>
</ul>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Methods"><strong>Methods</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Notation:
</p>
<p>
<strong>$</strong> [ <strong>{</strong> ][ <strong>a..z</strong>,
<strong>A..Z</strong> ][ <strong>a..z</strong>, <strong>A..Z</strong>,
<strong>0..9</strong>, <strong>-</strong>, <strong>_</strong> ]*
<strong>.</strong>[ <strong>a..z</strong>, <strong>A..Z</strong> ][
<strong>a..z</strong>, <strong>A..Z</strong>, <strong>0..9</strong>,
<strong>-</strong>, <strong>_</strong> ]*<strong>(</strong> [
<i>opional parameter list...</i> ] <strong>)</strong> [
<strong> } </strong>]
</p>
<p>
Examples:
</p>
<ul>
<li>Regular Notation: $customer.getAddress()</li>
<li>Formal Notation: ${purchase.getTotal()}</li>
<li>Regular Notation with Parameter List: $page.setTitle( "My Home
Page" )</li>
</ul>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<p>
VTL Properties can be used as a shorthand notation for VTL Methods
that take <em>get</em> and <em>set</em>. Either
<em>$object.getMethod()</em> or <em>$object.setMethod()</em> can be
abbreviated as <em>$object.Method</em>. It is generally preferable to
use a Property when available. The main difference between Properties
and Methods is that you can specify a parameter list to a Method.
</p>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Directives"><strong>Directives</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="#set - Establishes the value of a reference"><strong>#set - Establishes the value of a reference</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Format:
</p>
<p>
<strong>#set( $</strong>ref <strong>=</strong> [ <strong>"</strong>,
<strong>'</strong> ]arg[ <strong>"</strong>, <strong>'</strong> ] )
</p>
<p>
Usage:
</p>
<ul>
<li><em>$ref</em> - The LHS of the assignment must be a variable
reference or a property reference.</li>
<li><em>arg</em> - The RHS of the assignment, <em>arg</em> is parsed
if enclosed in double quotes, and not parsed if enclosed in single
quotes. If the RHS evaluates to <em>null</em>, it is <b>not</b>
assigned to the LHS.</li>
</ul>
<p>
Examples:
</p>
<ul>
<li>Variable reference: #set( $monkey = "bill" )</li>
<li>String literal: #set( $monkey.Friend = "monica" )</li>
<li>Property reference: #set( $monkey.Blame = $whitehouse.Leak
)</li>
<li>Method reference: #set( $monkey.Plan = $spindoctor.weave($web)
)</li>
<li>Number literal: #set( $monkey.Number = 123 )</li>
<li>Range operator: #set( $monkey.Numbers = [1..3] )</li>
<li>Object array: #set( $monkey.Say = ["Not", $my, "fault"] )</li>
</ul>
<p>
The RHS can also be a simple arithmetic expression, such as:
</p>
<ul>
<li>Addition: #set( $value = $foo + 1 )</li>
<li>Subtraction: #set( $value = $bar - 1 )</li>
<li>Multiplication: #set( $value = $foo * $bar )</li>
<li>Division: #set( $value = $foo / $bar )</li>
<li>Remainder: #set( $value = $foo % $bar )</li>
</ul>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="#if / #elseif / #else - output conditional on truth of statements"><strong>#if / #elseif / #else - output conditional on truth of statements</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Format:
</p>
<p>
<strong>#if(</strong> [condition] <strong>)</strong> [output] [
<strong>#elseif( </strong>[condition] <strong>)</strong> [output] ]* [
<strong>#else</strong> [output] ]
<strong>#end</strong>
</p>
<p>
Usage:
</p>
<ul>
<li><em>condition</em> - If a boolean, considered true if it has a
true false; if not a boolean, considered true if not null.</li>
<li><em>output</em> - May contain VTL.</li>
</ul>
<p>
Examples:
</p>
<ul>
<li>Equivalent Operator: #if( $foo == $bar )</li>
<li>Greater Than: #if( $foo > 42 )</li>
<li>Less Than: #if( $foo < 42 )</li>
<li>Greater Than or Equal To: #if( $foo >= 42 )</li>
<li>Less Than or Equal To: #if( $foo <= 42 )</li>
<li>Equals Number: #if( $foo == 42 )</li>
<li>Equals String: #if( $foo == "bar" )</li>
<li>Boolean NOT: #if( !$foo )</li>
</ul>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="#foreach - Loops through a list of objects"><strong>#foreach - Loops through a list of objects</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Format:
</p>
<p>
<strong>#foreach(</strong> <em>$ref</em> <strong>in</strong> <em>arg</em>
<strong>)</strong> <em>statement</em> <strong>#end</strong>
</p>
<p>
Usage:
</p>
<ul>
<li><em>$ref</em> - The first variable reference is the item.</li>
<li><em>arg</em> - May be one of the following: a reference to a
list (i.e. object array, collection, or map), an array list, or
the range operator.</li>
<li>
<em>statement</em> - What is output each time Velocity finds a
valid item in the list denoted above as <i>arg</i>. This output is
any valid VTL and is rendered each iteration of the loop.
</li>
</ul>
<p>
Examples of the #foreach(), omitting the statement block :
</p>
<ul>
<li>Reference: #foreach ( $item in $items )</li>
<li>Array list: #foreach ( $item in ["Not", $my, "fault"] )</li>
<li>Range operator: #foreach ( $item in [1..3] )</li>
</ul>
<p>
Velocity provides an easy way to get the loop counter so that you
can do something like the following:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
<table>
#foreach( $customer in $customerList )
<tr><td>$velocityCount</td><td>$customer.Name</td></tr>
#end
</table>
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
The default name for the loop counter variable reference, which is
specified in the velocity.properties file, is $velocityCount. By
default the counter starts at 1, but this can be set to either 0 or
1 in the <code>velocity.properties</code> file. Here's what the loop
counter properties section of the <code>velocity.properties</code>
file appears:
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
# Default name of the loop counter
# variable refernce.
counter.name = velocityCount
# Default starting value of the loop
# counter variable reference.
counter.initial.value = 1
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="#include - Renders local file(s) that are not parsed by Velocity"><strong>#include - Renders local file(s) that are not parsed by Velocity</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Format:
</p>
<p>
<strong>#include( </strong>arg[, arg2, ... argn]<strong> )</strong>
</p>
<ul>
<li><em>arg</em> - Refers to a valid file under TEMPLATE_ROOT.</li>
</ul>
<p>
Examples:
</p>
<ul>
<li>String: #include( "disclaimer.txt", "opinion.txt" )</li>
<li>Variable: #include( $foo, $bar )</li>
</ul>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="#parse - Renders a local template that is parsed by Velocity"><strong>#parse - Renders a local template that is parsed by Velocity</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Format:
</p>
<p>
<strong>#parse(</strong> arg <strong>)</strong>
</p>
<ul>
<li><em>arg</em> - Refers to a template under TEMPLATE_ROOT.</li>
</ul>
<p>
Examples:
</p>
<ul>
<li>String: #parse( "lecorbusier.vm" )</li>
<li>Variable: #parse( $foo )</li>
</ul>
<p>
Recursion permitted. See <em>parse_directive.maxdepth</em> in
<code>velocity.properties</code>
to change from parse depth. (The default parse depth is 10.)
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="#stop - Stops the template engine"><strong>#stop - Stops the template engine</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Format:
</p>
<p>
<strong>#stop</strong>
</p>
<p>
Usage:
</p>
<p>
This will stop execution of the current template. This is good for
debugging a template.
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="#macro - Allows users to define a Velocimacro (VM), a repeated segment of a VTL template, as required"><strong>#macro - Allows users to define a Velocimacro (VM), a repeated segment of a VTL template, as required</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Format:
</p>
<p>
<strong>#macro(</strong> vmname $arg1 [ $arg2 $arg3 ... $argn ]
<strong>)</strong> [ VM VTL code... ] <strong>#end</strong>
</p>
<ul>
<li><em>vmname</em> - Name used to call the VM
(<em>#vmname</em>)</li>
<li><em>$arg1 $arg2 [ ... ]</em> - Arguments to the VM. There can be
any number of arguments, but the number used at invocation must
match the number specified in the definition.</li>
<li><em>[ VM VTL code... ]</em> - Any valid VTL code, anything you
can put into a template, can be put into a VM.</li>
</ul>
<p>
Once defined, the VM is used like any other VTL directive in a
template.
</p>
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>
#vmname( $arg1 $arg2 )
</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<p>
VMs can be defined in one of two places:
</p>
<ol>
<li><i>Template library:</i> can be either VMs pre-packaged with
Velocity or custom-made, user-defined, site-specific VMs;
available from any template</li>
<li><i>Inline:</i> found in regular templates, only usable when
<em>velocimacro.permissions.allowInline=true</em> in
<code>velocity.properties</code>.</li>
</ol>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Comments"><strong>Comments</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Comments are not rendered at runtime.
</p>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Single Line"><strong>Single Line</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Example:
</p>
<p>
<strong>## This is a comment.</strong>
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="Multi Line"><strong>Multi Line</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Example:
</p>
<p>
<strong>
#*<br />
This is a multiline comment.<br />
This is the second line<br />
*#
</strong>
</p>
</blockquote>
</td></tr>
<tr><td><br/></td></tr>
</table>
</blockquote>
</p>
</td></tr>
<tr><td><br/></td></tr>
</table>
</td>
</tr>
<!-- FOOTER -->
<tr><td colspan="2">
<hr noshade="" size="1"/>
</td></tr>
<tr><td colspan="2">
<div align="center"><font color="#525D76" size="-1"><em>
Copyright © 1999-2004, The Apache Software Foundation
</em></font></div>
</td></tr>
</table>
</body>
</html>
<!-- end the processing -->
|