Previous Chapter | Next Chapter | Up | Next Section | Contents

Displaying Objects with the with Tag


The with tag can be used to expand the namespace of a document template by adding attributes (or mapping keys) from an object which already exists in the document template namespace. For example, if a document template is used to display a folder, the contents of a sub-folder can be displayed using a with tag:

<!--#with subfolder-->
<!--#var title-->
<!--#/with-->

In combination with the namespace method of the special variable, _, the with tag can be used to add new variables to the DTML name space:

<!--#with "_.namespace(profit=price-cost, title=product_name+' summary')"-->
<h3><!--#var title--></h3>
The profit is <!--#var profit-->
<!--#/with-->

A common use of the with tag is to cause request variables to be used before object attributes:

The current id is <!--#var id-->
<!--#with REQUEST-->
The id you entered was <!--#var id-->
<!--#/with-->

Normally, document templates are used as methods of objects. Object attributes commonly take precedence over request variables. Using the REQUEST variable in a with tag causes the request to be searched before other parts of the name space.

Previous Chapter | Next Chapter | Up | Next Section | Contents

SUBSECTIONS