> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fileloom.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Logic Helpers

> Perform boolean operations with and, or, not, isEmpty, isNotEmpty, ternary, and default.

Logic helpers perform boolean operations and provide fallback values.

## and

Returns `true` if ALL arguments are truthy.

```handlebars theme={null}
{{and true true}}
```

**Output:** `true`

```handlebars theme={null}
{{and true false}}
```

**Output:** `false`

```handlebars theme={null}
{{#if (and isActive isPaid hasStock)}}
  <button>Buy Now</button>
{{/if}}
```

**Multiple arguments:**

```handlebars theme={null}
{{#if (and condition1 condition2 condition3 condition4)}}
  All conditions met!
{{/if}}
```

## or

Returns `true` if ANY argument is truthy.

```handlebars theme={null}
{{or false true}}
```

**Output:** `true`

```handlebars theme={null}
{{#if (or isAdmin isModerator isOwner)}}
  <button>Edit</button>
{{/if}}
```

## not

Inverts a boolean value.

```handlebars theme={null}
{{not true}}
```

**Output:** `false`

```handlebars theme={null}
{{#if (not isDeleted)}}
  <div class="item">...</div>
{{/if}}

{{#if (not (eq status "archived"))}}
  <button>Archive</button>
{{/if}}
```

## isEmpty

Returns `true` if the value is empty (null, undefined, empty string, empty array, or empty object).

```handlebars theme={null}
{{isEmpty ""}}
```

**Output:** `true`

```handlebars theme={null}
{{isEmpty []}}
```

**Output:** `true`

```handlebars theme={null}
{{#if (isEmpty items)}}
  <p>No items found.</p>
{{else}}
  {{#each items}}...{{/each}}
{{/if}}

{{#if (isEmpty notes)}}
  <p class="no-notes">No additional notes</p>
{{else}}
  <p>{{notes}}</p>
{{/if}}
```

## isNotEmpty

Returns `true` if the value is NOT empty.

```handlebars theme={null}
{{isNotEmpty "hello"}}
```

**Output:** `true`

```handlebars theme={null}
{{#if (isNotEmpty customer.phone)}}
  <p>Phone: {{customer.phone}}</p>
{{/if}}

{{#if (isNotEmpty attachments)}}
  <h3>Attachments</h3>
  {{#each attachments}}...{{/each}}
{{/if}}
```

## ternary

Returns one value if condition is true, another if false (inline if-else).

```handlebars theme={null}
{{ternary condition "yes" "no"}}
```

| Argument    | Type | Description                  |
| ----------- | ---- | ---------------------------- |
| `condition` | any  | Value to test for truthiness |
| `ifTrue`    | any  | Value to return if true      |
| `ifFalse`   | any  | Value to return if false     |

**Examples:**

```handlebars theme={null}
{{ternary isPaid "Paid" "Unpaid"}}
```

```handlebars theme={null}
<span class="{{ternary isActive 'active' 'inactive'}}">
  {{ternary isActive "Active" "Inactive"}}
</span>
```

```handlebars theme={null}
<tr class="{{ternary (eq (modulo @index 2) 0) 'even' 'odd'}}">
```

## default

Returns a default value if the primary value is null, undefined, or empty string.

```handlebars theme={null}
{{default value "fallback"}}
```

| Argument       | Type | Description                  |
| -------------- | ---- | ---------------------------- |
| `value`        | any  | Primary value to check       |
| `defaultValue` | any  | Fallback if primary is empty |

**Examples:**

```handlebars theme={null}
{{default customer.nickname customer.name}}
```

```handlebars theme={null}
<p>Notes: {{default notes "No additional notes"}}</p>
```

```handlebars theme={null}
<img src="{{default user.avatar '/images/default-avatar.png'}}" alt="Avatar">
```

## Combining Logic Helpers

### Complex Conditions

```handlebars theme={null}
{{! Show button if active AND (admin OR owner) }}
{{#if (and isActive (or isAdmin isOwner))}}
  <button>Manage</button>
{{/if}}

{{! Show if not empty and not archived }}
{{#if (and (isNotEmpty items) (not isArchived))}}
  <ul>{{#each items}}<li>{{this}}</li>{{/each}}</ul>
{{/if}}
```

### Nested Ternary

```handlebars theme={null}
{{ternary isPaid "Paid" (ternary isOverdue "Overdue" "Pending")}}
```

## Practical Examples

### Status with Fallback

```handlebars theme={null}
<span class="status">
  {{default status "Unknown"}}
</span>
```

### Conditional CSS Classes

```handlebars theme={null}
<div class="card {{ternary isHighlighted 'highlighted' ''}} {{ternary isUrgent 'urgent' ''}}">
  ...
</div>
```

### Empty State Handling

```handlebars theme={null}
{{#if (isNotEmpty orders)}}
  <table>
    <thead>...</thead>
    <tbody>
      {{#each orders}}
        <tr>...</tr>
      {{/each}}
    </tbody>
  </table>
{{else}}
  <div class="empty-state">
    <p>No orders yet.</p>
    <a href="/products">Start shopping</a>
  </div>
{{/if}}
```

### Permission-Based UI

```handlebars theme={null}
{{#if (or isAdmin (and isEditor (not isLocked)))}}
  <button class="edit-btn">Edit</button>
{{/if}}

{{#if (and isOwner (not isArchived))}}
  <button class="delete-btn">Delete</button>
{{/if}}
```

### Optional Sections

```handlebars theme={null}
{{#if (isNotEmpty customer.company)}}
  <p class="company">{{customer.company}}</p>
{{/if}}

{{#if (isNotEmpty billingAddress)}}
  <div class="billing-address">
    <h4>Billing Address</h4>
    {{billingAddress}}
  </div>
{{/if}}
```

### Row Striping

```handlebars theme={null}
{{#each items}}
  <tr class="{{ternary (eq (modulo @index 2) 0) 'row-even' 'row-odd'}}">
    <td>{{this.name}}</td>
    <td>{{currency this.price "USD"}}</td>
  </tr>
{{/each}}
```
