quickadd
quickadd copied to clipboard
Add conditional logic support in templates
Summary
Add conditional logic (if-then-else) support in QuickAdd templates to enable dynamic content based on variable values.
Problem
Currently, templates are static and cannot adapt based on:
- Variable values entered by users
- File properties or metadata
- Date/time conditions
- Other dynamic factors
Use Cases
- Show different content based on note type:
{{IF:noteType==meeting}}## Attendees{{ELSE}}## Overview{{ENDIF}} - Conditional sections:
{{IF:priority==high}}⚠️ URGENT: {{ENDIF}} - Date-based logic:
{{IF:DATE:dddd==Monday}}## Weekly Review{{ENDIF}} - Variable-dependent formatting:
{{IF:project}}Project: {{project}}{{ENDIF}}
Proposed Syntax
{{IF:condition}}
Content when true
{{ELSEIF:condition2}}
Content when condition2 is true
{{ELSE}}
Default content
{{ENDIF}}
Supported Conditions
- Variable comparisons:
variable==value,variable\!=value - Existence checks:
variable(true if defined and not empty) - Date conditions:
DATE:format==value - Numeric comparisons:
variable>5,variable<=10
Benefits
- More dynamic and intelligent templates
- Reduced need for multiple similar templates
- Better user experience with contextual content
- More powerful automation possibilities
Implementation Notes
- Parse template for conditional blocks before variable substitution
- Evaluate conditions and include/exclude content accordingly
- Compatible with existing format syntax
- Could be optional feature for performance
You can do this with Templater syntax:
---
title: "{{VALUE:subject}}"
creation_date: "{{VALUE:entry_date}}"
tags: "{{VALUE:tags}}"
type: "journal_entry"
---
<%* if ("{{VALUE:subject}}" !== "") { %>
## {{VALUE:subject}}
<%* } -%>
{{VALUE:entry}}
The if is broken across lines note that for this the QuickAdd variables need to be quoted:
<%* if ("{{VALUE:subject}}" is JS Conditional ) { %>
My conditional content here
<%* } -%> //Closing bracket with whitespace eating