π§© AppML β Including HTML Templates: Reuse UI Components with Ease
π§² Introduction β Why Use HTML Includes in AppML?
Large web applications often have repeated UI elementsβheaders, footers, menus, or forms. Instead of duplicating HTML across files, AppML allows you to include external HTML templates using the appml-include
attribute. This improves maintainability, reusability, and clean architectureβwithout requiring any JavaScript libraries.
π― In this article, youβll learn:
- What
appml-include
does and how it works - How to include reusable UI components
- Nested includes and their limitations
- Best practices for templating in AppML
π What Is appml-include
?
The appml-include
attribute in AppML allows you to inject external HTML files into a parent HTML page.
β Basic Syntax
<div appml-include="header.html"></div>
π₯ This line tells AppML to fetch the contents of header.html
and inject them into the <div>
.
π Real Example β Common Layout Includes
Letβs build a layout with reusable pieces:
β
header.html
<header>
<h1>My AppML App</h1>
</header>
β
footer.html
<footer>
<p>Β© 2025 MyCompany</p>
</footer>
β
index.html
<body>
<div appml-include="header.html"></div>
<main>
<p>Welcome to our AppML-powered site!</p>
</main>
<div appml-include="footer.html"></div>
</body>
π Result: AppML dynamically pulls in header.html
and footer.html
.
π§ͺ Include with AppML Logic Inside
You can include components that use appml-data
, appml-controller
, or appml-model
.
β
user-list.html
<div appml-data="data/users.json">
<p>{{name}} β {{email}}</p>
</div>
β
dashboard.html
<div appml-include="user-list.html"></div>
AppML processes all AppML-specific attributes even inside includes.
π¦ Nested Includes: Supported with Caution
You can nest includes inside other included files:
<!-- dashboard.html -->
<div appml-include="layout.html"></div>
<!-- layout.html -->
<div appml-include="navbar.html"></div>
<main> ... </main>
β οΈ However, deep nesting may lead to performance or debugging issues. Limit to 2β3 levels.
π οΈ Use Case: Reusable Form Components
β
input-text.html
<label>{{label}}</label>
<input name="{{field}}" type="text">
You can dynamically load this component multiple times with different bindings:
<div appml-include="input-text.html" appml-data="data/name.json"></div>
<div appml-include="input-text.html" appml-data="data/email.json"></div>
β Great for standardized input designs.
π‘ Best Practices for Using appml-include
β Tip | π¬ Reason |
---|---|
Store includes in a /components/ folder | Keeps your project organized |
Use includes for headers, footers, navs | Avoid HTML repetition |
Limit nesting to 2β3 levels | Prevent debugging complexity |
Avoid large file sizes in includes | Reduces load time |
Always test with and without JavaScript | AppML doesn’t need JS, but your other scripts might |
π Summary β Recap & Key Takeaways
The appml-include
attribute empowers developers to reuse components and maintain consistency across pages. It fits perfectly into AppMLβs low-code, component-driven philosophy.
π Key Takeaways:
- Use
appml-include="file.html"
to reuse HTML templates - Includes support nested
appml-*
logic like data, models, and controllers - Great for headers, navbars, forms, and reusable UI parts
- Organize includes into folders for scalability
- Minimize deep nesting and large includes for performance
βοΈ With includes, AppML becomes a modular, maintainable frameworkβeven without JavaScript!
β FAQs β Including HTML Templates in AppML
β Can I use includes with dynamic data in AppML?
β
Yes. Included files can have appml-data
, appml-model
, or any other AppML logic.
β Are nested includes supported?
β
Yes, but limit nesting depth to avoid complexity and longer load times.
β Can I include full HTML documents (with <html>
tags)?
β No. Includes should only contain fragments like <div>
, <section>
, etc., not full documents.
β How does AppML handle missing include files?
β οΈ It silently fails. Use browser dev tools (F12) to check for 404 errors and test paths.
β Is appml-include
processed after page load?
β
Yes. It runs during AppMLβs initialization, before data is rendered.
Share Now :