webCOMAND

#LIST

Processes and outputs cScript between #LIST() and #ENDLIST for each item in a Publication List or collection.

Prototype

#LIST($list, ...) ... #ENDLIST

Parameters

  • list - One of the following:
    • Identifier of Publication List - Process a Publication List in the current cScript context and iterate through the results.
    • Variable contain a Collection - A variable containing a collection of objects, such as a field that contains a list, or a variable set with #CQL, #CPATH or #SQL.
    • Inline Query - A cPath or cQL query can be specified inside ${}.
  • ... - Optional parameters to pass to the Publication List, which will be available in the Publication List Filter and Order/Limit as $A, $B and so on.

Processing Iterations

The block of code between the #LIST() and #ENDLIST will be processed repeatedly, for each item in the list.

Iteration Object & Field Variables

Each item in the list is a cTemplate object where:

  • $this - The object of the current iteration can be accessed from the $this variable.
  • $field - All of the top-level fields of the object can be access directly from a variable named after their field identifier.

For example, the value of the Title field the object can be listed in either of the following ways:

  • ${this.Title}
  • $Title

Query SELECT clauses

The SELECT clause of the query a list is based on can affect field variables and their values and impact performance.

  • No SELECT - If no SELECT clause is specified in the list query, field values will be loaded on-demand when they are first accessed, which is less efficient than including the fields you will access in the SELECT clause to preload them.  For more information, see Populating the Object Cache.
  • SELECT deep dot-notation fields - In addition to the more obvious top-level fields, subfield values for objects referenced or embedded within the selected object can also be pre-loaded to improve performance.  Since the object structure is loaded, SELECTED deep dot-notation fields will be pre-loaded into the object structure, and not flattened into field variables at the top-level of the object, like a traditional SQL query or SELECT alias (see next bullet) would.
  • SELECT aliases - When a SELECT clause includes an "AS" alias, the value selected will be available in a variable named after the specified alias.  If the alias matches the name of a field, the alias value will override the field value and the field value will not be accessible.  For more information, see cQL SELECT Aliases.
For more information about how objects are loaded and cached from queries, see Repository Object Cache

Examples

Publication List

#/ List events from a Publication List with the Identifier "Events"
#LIST(Events)
$Date - $Description
#ENDLIST

Variable

#/ List events in a Venue's Events list field
#CONTEXT(Venue,OID=123)
    #LIST($Events)
$Date - $Description
    #ENDLIST
#ENDCONTEXT

Query

#/ List events in a Venue's Events list field
#CQL($Events,"FROM Event WHERE @(Events)Venue.OID=123")
#LIST($Events)
$Date - $Description
#ENDLIST

Inline cPath Query

#/ List events in a Venue's Events list field
#LIST(${[:Venue AND OID=123].Events})
$Date - $Description
#ENDLIST

Inline cQL Query

#/ List events in a Venue's Events list field
#LIST(${FROM Event WHERE @(Events)Venue.OID=123})
$Date - $Description
#ENDLIST

Content Source Errors

cTemplate can be processed in different environments, including for a Publication or when writing a File object within a Package that is configured to write File objects to the file system upon store, save and/or approve.  If #LIST() is processed when writing a File object within a Package to the file system and the Publication List has a Content Source that relative to the Publication's Content Folder, it will result in an error like:

Publication List X Content Source (Publication's Content Folder) not available in processing environment.

When this happens, it means that the cTemplate processor cannot resolve the Publication List's Content Source because there is no Publication to reference for the Content Folder.  In this case, there are a few possible solutions:

  1. If the File objects are in a Package that does not require the File objects to be written to the file system, because they only need to be published, uncheck the Write Files checkbox within the Package that contains the File object.
  2. If some File objects in the same Package should be written on store, save and/or approve, but this File object does not need to be written, add the following cTemplate code to the first line of the File to prevent it from getting written or processed further.
    #IF(!$Publication)#RETURN(FALSE)#ENDIF
  3. If this File object does need to be written to the file system on store, save or approve, adjust the Publication List's Content Source to one that does not reference a Publication.

Related

#CQL, #CPATH, #SQL