Template Behaviors

Template behaviors define building logics for page production.
Do you want create a single output page or one page for each item in certain collection?
This is what you can manage through Template Behaviors.

Declaring a Template Behavior

Template Behaviors are stored in “expression” field of template entity (template entities are contained into “templates” collection). For further details about “templates” collection see: “Collection: TEMPLATES“.
This is a short example of template entity (remember that all entities can be customized with any imported field value):

{
“uid”:”GROUP”,
expression“:”items.GROUP:class1=STAIR.uid“,
“_id”:”720909A4B948FC9E33633B61960D6B3C”,
“style”:”sample”,
“description”:”this is template #GROUP”,
“parent”:”CB4AE3B37047FB4B2C0D16F8BF84F076″,
“rawhead”:”",
“rawhtml”:”"
}

Template Behavior Syntax

Template Behavior syntax is very  simple and matches this pattern:
collection-name. MODE:select-expression.output-field

Let start analyze each expression component:

  • collection-name: Name of an existing collection. Usually it’s “items” (default collection to host your products), but you can use every custom collection you may need (for ex. “articles”, “products”, etc..)
  • MODE: Template Behavior mode. One between supported modes.
  • select-expression: (Optional) a filter for your collection. This is an optional parameter and you can omit writing “collection-name. MODE.output-field“ (the shorthand pattern).
    Select expressions have their own syntax: field-name=value. You can concatenate more select expression using & like this: field-name1=value1&field-name2=value2.
  • output-field: Name of field which value will be used as output file name (only if MODE is REPEAT). If MODE is not “REPEAT”, this is an optional parameter and you can use this pattern:
    collection-name. MODE:select-expression or collection-name. MODE (the select-expression is always optional)

 

Deep into Template Behaviors

Here are some examples of valid Template Behavior Expressions:

  • items.GROUP : Behavior: Selects all entities in “items” collection.
    Output: Generates a single page which name is the template uid
  • items.GROUP:class1=MYCLASS Behavior: Selects all entities in “items” collection which “class1″ field value is “MYCLASS”.
    Output: Generates a single page which name is the template uid
  • items.GROUP:class1=MYCLASS.uid Behavior: Selects all entities in “items” collection which “class1″ field value is “MYCLASS”. “uid” optional parameter is ignored.
    Output: Generates a single page which name is the template uid
  • items.REPEAT.uidBehavior: Selects all entities in “items” collection.
    Output: Generates one page for each item in items collection. Page names are equals at uid field value of each item.
  • items.REPEAT:class1=MYCLASS.uidBehavior: Selects all entities in “items” collection.
    Output: Generates one page for each item in items collection. Page names are equals at uid field value of each item.

Supported Template Behavior’s modes:

  • GROUP: The template produce in output only one page
  • REPEAT: The template produce in output many pages, one for each item in collection