Template Syntax ​
STX uses an intuitive template syntax that extends HTML with additional features. This guide covers all the template syntax features available in STX.
Basic Syntax ​
Text Interpolation ​
Use double curly braces for text interpolation:
html
<div>{{ message }}</div>
Attributes ​
Bind attributes using the :
shorthand:
html
<button :disabled="isLoading">Submit</button>
Raw HTML ​
Use {{{ }}}
for raw HTML interpolation (use with caution):
html
<div>{{{ rawHtml }}}</div>
Directives ​
Conditional Rendering ​
html
<div @if="condition">Shown if true</div>
<div @else-if="otherCondition">Alternative</div>
<div @else>Fallback</div>
List Rendering ​
html
<ul>
<li @each="item in items" :key="item.id">
{{ item.name }}
</li>
</ul>
Event Handling ​
html
<button @click="handleClick">Click me</button>
<form @submit.prevent="handleSubmit">...</form>
Two-way Binding ​
html
<input @model="searchText">
Advanced Features ​
Dynamic Components ​
html
<component :is="componentName"></component>
Slots ​
html
<template #default>Default content</template>
<template #named>Named slot content</template>
Custom Directives ​
html
<div @custom-directive="value"></div>
Best Practices ​
- Always use key attributes with
@each
directives - Prefer
@if
over@show
for conditional rendering - Use computed properties for complex template expressions
- Keep template expressions simple and readable
TypeScript Support ​
STX templates fully support TypeScript, providing type checking for:
- Component props
- Event handlers
- Template expressions
- Directive arguments