Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
You can make your templates less cumbersome using the contextual object member access feature. This feature enables you to access members of some objects without specifying the objects' identifiers in template expressions. An object to which the feature can be applied is determined depending on a context as follows:
Obviously, inside a data band body, you can not use the feature to access members of an outer iteration variable or a passed data source object. With the exception of this restriction, you can use both contextual and common object member access syntaxes interchangeably depending on your needs and preferences.
Consider the following example. Given that ds is a DataSet instance containing a DataTable object named “Persons” that has fields named “Name” and “Age”, you can use the following template to list the contents of the table.
| No. | Name | Age |
| <<foreach [p in ds.Persons]>><<[ p.numberOf()]>> | <<[p.Name]>> | <<[p.Age]>><</foreach>> |
| Count: <<[ds.Persons.count()]>> | ||
Alternatively, you can use the following template involving the contextual object member access syntax to get the same results.
| No. | Name | Age |
| <<foreach [ in Persons]>><<[ numberOf()]>> | <<[Name]>> | <<[Age]>><</foreach>> |
| Count: <<[Persons.count()]>> | ||
Q: How does contextual object member access differ from regular member access in template expressions?
A: Contextual access lets you omit the object identifier; the engine automatically resolves the member to the innermost iteration variable (inside a data band) or to the passed data source (outside a data band). Regular access requires you to specify the full path, such as ds.Persons.Name.
Q: Can I use contextual object member access to reference an outer iteration variable from within a nested loop?
A: No. Inside a data band, contextual access always resolves to the innermost iteration variable. To reach an outer variable you must use the regular object member syntax with the appropriate identifier.
Q: How can I count the number of items in a data source using contextual syntax?
A: Use the count() method on the collection name without a prefix, e.g., <<[Persons.count()]>> when the template is outside a data band, or <<[count()]>> inside a foreach that iterates over Persons.
Q: What happens if I try to use contextual member access outside a data band body?
A: The engine resolves the member to the passed data source object. If no data source is supplied, the expression will fail with a “member not found” error. In such cases, specify the full data source identifier.
Q: Is it possible to mix contextual and regular member access in the same template?
A: Yes. You can use contextual syntax where it is allowed and fall back to regular syntax for cases that require explicit object references, such as accessing outer loop variables or when you need clarity in complex templates.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.