π§° AppML β Prototypes and Templates: Build Reusable and Dynamic UI Blocks
π§² Introduction β What Are Prototypes and Templates in AppML?
AppML makes it easy to reuse UI components across pages using prototypes and templates. These features allow you to separate logic from layout, reduce redundancy, and create dynamic content blocks that update automatically when data changes.
π― In this guide, youβll learn:
- What prototypes and templates mean in AppML
- How to use
appml-include
for reusable HTML blocks - How to define template-driven rendering for lists and forms
- Best practices for building dynamic, maintainable web components with AppML
π§± What Are Prototypes and Templates in AppML?
Term | Definition |
---|---|
Prototype | A reusable base layout or UI structure loaded into multiple pages |
Template | A block of HTML that gets repeated for each data record using {{ }} |
AppML allows you to include prototype files and define repeatable templates for rendering data-driven content without writing any JavaScript.
π Basic Example β Using appml-include
You can use appml-include
to insert reusable HTML sections like headers, footers, or UI forms.
β
header.html
<header>
<h1>My AppML Application</h1>
</header>
β Usage in Main Page
<div appml-include="header.html"></div>
This injects the entire content of header.html
into the pageβideal for navigation bars, page headers, or standard footers.
π Template Example β Displaying a List of Records
AppML uses HTML blocks containing {{ }}
expressions as inline templates to render each record.
β
Sample Data β data/products.json
[
{ "id": 1, "name": "Laptop", "price": 1200 },
{ "id": 2, "name": "Phone", "price": 800 }
]
β Main Page
<div appml-data="data/products.json">
<p>{{name}} β ${{price}}</p>
</div>
Each <p>
block is treated as a template and rendered for each object in the JSON array.
π¦ Using Templates with Models and Controllers
You can combine templates with models for structured layout and validation:
<div
appml-data="data/products.json"
appml-model="models/product-model.json"
appml-controller="controllers/product.js">
<h2>Product List</h2>
<p>{{name}} β ${{price}}</p>
</div>
βοΈ This pattern helps keep logic, structure, and layout modular and reusable.
π§© Prototypes vs Templates β What’s the Difference?
Feature | Prototypes | Templates |
---|---|---|
Purpose | Reuse layout/UI across pages | Repeat HTML block for each data record |
Keyword Used | appml-include="file.html" | Inline {{ }} inside appml-data blocks |
Usage | Navigation, forms, headers, footers | Lists, tables, item displays |
Scope | Across full application | Within a data-bound component |
π Dynamic Template Example β Filtering Product Templates
<input placeholder="Filter by price"
oninput="myAppML.filter='price > '+this.value">
The template dynamically updates as users interact with the input.
π§ Best Practices for Prototypes and Templates
β Practice | π Benefit |
---|---|
Use appml-include for shared elements | Promotes DRY (Donβt Repeat Yourself) |
Define one template block per data source | Prevents confusion and layout bugs |
Use semantic HTML inside templates | Improves SEO and accessibility |
Keep templates short and data-focused | Makes it easier to style and maintain |
Store includes in a separate folder | Example: /components/header.html |
π Summary β Recap & Key Takeaways
AppML provides powerful support for prototypes and templates, letting you build reusable layouts and repeatable data blocks in a clean, declarative way. Whether you’re including headers or displaying 100 product cards, these features make development faster and more organized.
π Key Takeaways:
- Use
appml-include
to inject reusable layouts like headers or footers - Use
{{ }}
inside containers bound toappml-data
for templated rendering - Templates auto-repeat per data recordβno loops or JS required
- Pair templates with models/controllers for enhanced interactivity
- Great for lists, grids, dashboards, and admin interfaces
βοΈ Mastering AppML templates and prototypes helps you scale apps without cluttering your HTML or relying on complex logic.
β FAQs β AppML Prototypes and Templates
β Can I include multiple templates in one file?
β
Yes, but only one template block will be used per data-bound component. Use clear separation.
β Do appml-include
blocks support nested includes?
β
Yes. You can include a file that itself uses appml-include
.
β Can I apply different templates to different data types?
β
Yes. Simply create different <div appml-data="...">
blocks and design each layout uniquely.
β Can I reuse a form as a prototype?
β
Absolutely. Wrap your form in a separate file and include it with appml-include
.
β Does appml-include
load content synchronously?
β
Yes. It loads HTML into the DOM when AppML initializes the page.
Share Now :