webCOMAND

cTemplate Methods

cTemplate Methods are used to customize what happens when content is added, updated, copied, removed and displayed, in webCOMAND or through the APIs.  For example, when a Contact is added or updated, we may want to:

  • Display the contact in "Full Name <Email>" format in webCOMAND.
  • Crop and resize their profile photo if too large.
  • Email the contact to let them know they have been added/updated.
  • Sync their information to a third-party CRM.

cTemplate Methods make it possible to add these types of custom behaviors.

Recognized Methods

The following methods are recognized and may be used to modify the default behavior.

  • New - Called just after an object is created with its default values (by the repository new_object method), to initialize fields to default values and otherwise prepare for the new object. If one or more errors are logged to the event log, the new process will be cancelled and fail.
  • Summary - When an object is referenced as a string, it will automatically produce a string representation of the object based on the content type. The Summary method can override COMAND's default rules. For details, see Object Summary.
  • Description - Called when an object is updated to produce and cache a brief description, which is included in list view, etc.
  • Icon - Called when an object is updated to produce and cache an image blob to represent the object.  WARNING: Cached icons are accessible by any user that can login to webCOMAND.  User's do not need to have access to the specific object to access to the icon, so icons should not reveal any sensitive information about the object it represents.
  • Key - Every object is assigned a string that uniquely identifies it from all other objects of the same content type. Ideally, it is a human-readable string. The UniqueIdentifier method can override COMAND's default method. For more information, see object class Key.
  • Keywords - Called when an object is updated to produce and cache a set of keywords that can be searched in webCOMAND and with the API Search Framework.
  • Validate - Called just before an object is approved or saved to validate field values and potentially perform additional tasks to prepare to approve/save the object.  If one or more errors are logged to the event log, the approve/save process will be cancelled and fail.  If the Validate method returns false, the validation process will end without proceeding to field validations.
  • Image - Called to produce the binary image file data from content that can be inserted into a rich text field.  Content can be inserted into a rich text field if the ImageHTML content type method (see next) is defined for the content's content type.  For more information, see Rich Text Editor Customization.
  • ImageHTML - Called to produce the HTML image tag for a content type that can be inserted as an image into a rich text field.  For more information, see Rich Text Editor Customization.
  • Save - Called immediately after an object is saved.
  • Store - Called immediately after an object is stored.
  • Submit - Called after the more specific Approve, Save or Store content type method is called, for all cases.  This is useful because it is always called no matter how an object is updated.
  • Approve - Called immediately after an object is approved.
  • Copy - Called just after an object is copied, to update fields and otherwise prepare for the operation. If one or more errors are logged to the event log, the process will be cancelled and fail.
  • Delete - Called just before an object is deleted, to prepare for the operation. If one or more errors are logged to the event log, the process will be cancelled and fail. If a value is returned, the operation will be cancelled, but not fail. A return value can be useful when an object should be moved or modified instead of getting deleted.
  • Move - Called just after an object is moved, to update fields and otherwise prepare for the operation. If one or more errors are logged to the event log, the process will be cancelled and fail.

Add a cTemplate Method to a Content Type

The following Summary cTemplate example will cause webCOMAND to display Contacts in "First Name Last Name <Email>" format.

  1. Add or Open a "Contact" Content Type in Content Type Editor View, with field for the contact's First Name, Last Name and Email.
  2. Click the Templates option in the upper-right.
  3. Add a Template with "Summary" for the Identifier.
  4. Enter the following cTemplate code on the right.
    $FirstName $LastName <$Email>
  5. Approve the Content Type.
When a Content Type's Summary Template is changed, each object's summary is not updated automatically.  It will be updated the next time the object is updated, or you can Refresh Cache from the Repositories App.