# FirstSpirit Template Functions Reference ## Overview FirstSpirit template functions provide powerful tools for conditional logic, content highlighting, and dynamic template behavior. These functions are essential for creating interactive, editable content experiences in both SiteArchitect and ContentCreator environments. ## Table of Contents 1. [editorId Function](#editorid-function) 2. [if Function](#if-function) 3. [Function Usage Best Practices](#function-usage-best-practices) --- ## editorId Function ### Purpose The `editorId()` function enables Content Highlighting and EasyEdit functionality in FirstSpirit's SiteArchitect and ContentCreator. It creates unique references to HTML elements within a page, allowing editors to click and edit content directly in the preview interface. ### Basic Syntax ``` $CMS_VALUE(editorId(editorName:"componentName"))$ ``` ### Parameters The `editorId()` function supports multiple parameters for controlling editing behavior: | Parameter | Type | Description | Scope | Required | |-----------|------|-------------|-------|----------| | `editorName` | String | UID of the input component to edit | All | Yes (in most cases) | | `language` | String | Specifies the language for form opening (e.g., "FR", "EN") | ContentCreator | No | | `entity` | Object | Entity object for database content editing | All | No | | `template` | Object/String | TableTemplate object or UID for structured content | All | No | | `view` | Object | Data source (Content2 object) for context | All | No | | `element` | Object | FirstSpirit objects like GCA or content areas | All | No | | `target` | Object | Identifies target objects when not directly determinable | All | No | | `previewRulesEvaluation` | Boolean | Controls rule evaluation (true/false) | ContentCreator | No | | `resolution` | String | Activates image cropping functionality | ContentCreator | No | | `reloadPreview` | Boolean | Refreshes entire page after edits | ContentCreator | No | | `reloadElement` | String | HTML element ID to reload after edits | ContentCreator | No | | `json` | Boolean | Returns JSON object instead of HTML fragment | ContentCreator | No | | `meta` | Boolean | Enables metadata editing via InEdit | ContentCreator | No | | `externalReference` | String | Supports external references with FS_INDEX | ContentCreator | No | ### Usage Examples #### Block-Level Highlighting Highlight an entire heading element for editing: ```html
$CMS_IF(!pt_text.isEmpty)$ $CMS_VALUE(pt_text)$ $CMS_ELSE$ $CMS_END_IF$
``` 2. **Place editorId in Opening Tag**: Always place the editorId function within the opening tag of the HTML element, before the closing `>`. 3. **Combine with Content Output**: Use editorId alongside actual content output to create a seamless editing experience. ### Availability Available since FirstSpirit Version 4.0 --- ## if Function ### Purpose The `if()` function evaluates conditions in a compact form, enabling conditional output within templates. It's the primary method for implementing conditional logic within `$CMS_VALUE$` instructions, commonly used to verify whether values are set before rendering content. ### Syntax ``` $CMS_VALUE( if( CONDITION_1, CONDITION_TRUE_1, CONDITION_2, CONDITION_TRUE_2, ..., CONDITION_N, CONDITION_TRUE_N, CONDITION_FALSE ) )$ ``` ### Parameters The `if()` function uses a variable-length parameter structure: 1. **CONDITION_n** (Required for first pair): Boolean expression or comparison 2. **CONDITION_TRUE_n** (Required for first pair): Output when condition is true 3. **CONDITION_FALSE** (Optional): Output when all conditions are false ### Parameter Requirements - A condition and corresponding true-branch execution are mandatory - All other condition/true-branch pairs are optional - Only one false-branch is permitted, regardless of the number of conditions - The function must be used within `$CMS_VALUE(...)$` instructions ### Condition Structure Conditions can be constructed using up to three components: 1. **Variable or constant** - The value to evaluate 2. **Operator** (optional) - Comparison or logical operator 3. **Comparable value** (optional) - The value to compare against Expressions that return Boolean values (e.g., `#global.preview`) don't require operators or comparison values. ### Evaluation Logic 1. Conditions are evaluated in order from first to last 2. The first condition that evaluates to true triggers its corresponding true-branch 3. If no conditions evaluate to true, the false-branch executes (if provided) 4. No output occurs if no condition is met and no false-branch exists ### Supported Operators Conditions support standard comparison and logical operators: - **Comparison**: `==`, `!=`, `<`, `>`, `<=`, `>=` - **Logical**: `&&` (AND), `||` (OR), `!` (NOT) - **String/Collection**: `isEmpty`, `isSet`, `contains` ### Usage Examples #### Simple Condition Check Check if preview mode is active: ``` $CMS_VALUE(if(#global.preview, "Preview Mode", "Live Mode"))$ ``` #### Field Validation Output default text when field is empty: ``` $CMS_VALUE(if(!lt_text.isEmpty, lt_text, "Link"))$ ``` #### Multiple Conditions Evaluate multiple conditions in sequence: ``` $CMS_VALUE( if( st_type == "news", "News Article", st_type == "blog", "Blog Post", st_type == "product", "Product Page", "Standard Page" ) )$ ``` #### Nested Logic with Boolean Expressions Complex condition with preview and content checks: ``` $CMS_VALUE( if( #global.preview && pt_draft.isEmpty, "Draft content not available in preview", !pt_draft.isEmpty, pt_draft, pt_published ) )$ ``` #### Loop-Based Conditional Output Use modulo operations within loops: ``` $CMS_FOR(item, items)$