π§© AppML β Reusable Component Creation: Modularize Your AppML Web Apps
π§² Introduction β Why Build Reusable Components in AppML?
In modern web development, component reusability improves maintainability, consistency, and developer efficiency. With AppML, you can create modular HTML structuresβlike forms, tables, headers, footers, and search barsβthat are reusable across multiple pages or apps using just HTML and AppML directives.
π― In this guide, youβll learn:
- How to create and reuse components using
appml-include - Combine components with
appml-dataandappml-model - Dynamic inputs and data placeholders using
{{ }} - Best practices for designing AppML-friendly components
π§© What Are Reusable Components in AppML?
Reusable components in AppML are HTML snippets or blocks that can be inserted multiple times across pages using the appml-include attribute. These can contain:
- Forms connected to models
- Data display blocks
- Menu bars and UI controls
- Pagination, filters, alerts, etc.
π§ͺ Example β Simple Input Component
β
components/input-text.html
<div class="input-group">
<label>{{label}}</label>
<input name="{{field}}" type="text">
</div>
You can dynamically load and bind this to different fields:
β Usage
<div appml-include="components/input-text.html" appml-data="data/label-name.json"></div>
<div appml-include="components/input-text.html" appml-data="data/label-email.json"></div>
β
label-name.json
{ "label": "Name", "field": "name" }
π§ AppML replaces {{label}} and {{field}} with actual values.
π§ͺ Example β Reusable Data Table Component
β
components/user-table.html
<table>
<tr>
<th>Name</th><th>Email</th>
</tr>
<tr appml-repeat="records">
<td>{{name}}</td><td>{{email}}</td>
</tr>
</table>
β Main Page
<div appml-data="api/users.php" appml-include="components/user-table.html"></div>
βοΈ This loads user data and injects it into the reusable table component.
π Use Components with Forms + Models
β
components/product-form.html
<form>
<input name="name">
<input name="price" type="number">
<button appml-submit>Save</button>
</form>
You can link this component with a model and data source anywhere:
<div
appml-model="models/product-model.json"
appml-data="api/save-product.php"
appml-controller="controllers/product.js"
appml-include="components/product-form.html">
</div>
π§ Tips for Designing Reusable AppML Components
| π‘ Tip | β Why It Helps |
|---|---|
Use placeholders ({{field}}) | Enables dynamic content injection |
| Avoid hardcoded field names | Keeps components flexible |
| Externalize logic in controllers | Keeps HTML component files clean |
Use appml-include in parent layout | Makes templating scalable |
Group components in /components/ dir | Organizes codebase clearly |
π Summary β Recap & Key Takeaways
Creating reusable components in AppML lets you modularize your web UI, reduce duplication, and maintain consistency across views. Using appml-include, data bindings, and dynamic placeholders, you can develop scalable, low-code web apps with better structure.
π Key Takeaways:
- Use
appml-includeto insert HTML templates dynamically - Combine with
appml-datato inject values using{{}} - Design forms, tables, headers, and alerts as reusable components
- Use models and controllers to handle logic separately
- Organize component files into dedicated folders for reuse
βοΈ Reusable components make your AppML apps cleaner, DRY (Don’t Repeat Yourself), and easier to update.
β FAQs β Reusable Components in AppML
β Can I use multiple includes in the same page?
β
Yes, each appml-include is independent and can load different HTML snippets.
β Can components include other components?
β
Yes, nested includes are supportedβbut keep nesting shallow to avoid complexity.
β How do I pass dynamic data into a component?
β
Use appml-data="..." with a JSON object, and bind placeholders using {{}} in the included file.
β Can I reuse forms with different models?
β
Yes, just change the appml-model and appml-data in the parent block while using the same form layout.
β Is appml-include processed before or after data loads?
β
Itβs processed before data rendering, so bindings are available immediately after include.
Share Now :
