html but templating language client side,
it has
- for loop
- if-else
- Import HTML as components
- All javascript functions will work
- listen for variable change
- auto update ui as variable change
more features will come if you contribute so please contribute and make it happen.
This library provides a suite of customizable components and utilities to enhance your HTML-based applications. From loaders to template parsing, custom loops, and conditional rendering, this library simplifies common tasks for developers building dynamic and interactive UIs.
- Installation
- Getting Started
- Library Features
- Utility Functions
- Directory Structure
- FAQs and Discussions
To use this library, simply include the script in your HTML file after the body tag this should be loaded at last after defining all custom components
:
<script src="https://cdn.jsdelivr.net/gh/KTBsomen/httl-s@main/statejs.js"></script>
Ensure your project has the necessary setup for JavaScript.
Here is an example of how to show a loader using this library:
<script>
loader.show(); // Displays the loader
setTimeout(() => loader.hide(), 3000); // Hides it after 3 seconds
</script>
This library provides reusable components such as loaders, custom loops, and more, helping you build dynamic UI elements effortlessly.
A customizable loader that can display a spinning animation and blur the background.
// Show loader with default animation
loader.show();
// Hide loader
loader.hide();
// Show loader with custom HTML
loader.show('<div class="my-custom-loader">Loading...</div>');
Monitor and react to changes in global variables dynamically.
watch('myState', (propName, value) => {
console.log(`${propName} changed to:`, value);
});
myState = 'newValue'; // Console logs: "myState changed to: newValue"
Parse dynamic JavaScript expressions embedded in HTML using {{}}
.
const template = '<p>Hello, {{ user.name }}</p>';
const parsedTemplate = parseTemplate(template); // Replaces {{ user.name }} with its evaluated value
document.body.innerHTML = parsedTemplate;
Render dynamic arrays or range-based loops directly in HTML.
<for-loop array="[1, 2, 3]" valueVar="item" indexVar="index" loopid="loop1">
<template loopid="loop1">
<p>Index: ${index}, Value: ${item}</p>
</template>
</for-loop>
<p>Index: 0, Value: 1</p>
<p>Index: 1, Value: 2</p>
<p>Index: 2, Value: 3</p>
Render elements based on conditions directly in HTML.
<condition-block ifid="condition1">
<if-condition value="5" eq="5" elseid="conditionElse">
<p>Condition is true!</p>
</if-condition>
<else-condition elseid="conditionElse">
<p>Condition is false!</p>
</else-condition>
</condition-block>
Include and render external HTML files dynamically.
<include-template file="components/header.html"></include-template>
This will load header.html
and replace the tag's content with the parsed HTML.
-
Convert Relative to Absolute URLs
const absoluteHtml = convertRelativeToAbsolute('<img src="./image.jpg">', 'https://example.com/');
-
Create Range Arrays
const rangeArray = createRangeArray(1, 10, 2); // [1, 3, 5, 7, 9]
-
Set State
Update UI components dynamically:setState({ loopid: 'loop1' });
Here’s how you can organize files when using this library:
project/
├── components/
│ ├── header.html
│ └── footer.html
├── scripts/
│ ├── library.js
│ └── main.js
└── index.html
A: Use the loader.show()
method with a custom HTML string as a parameter.
A: While primarily designed for vanilla JavaScript, parts of the library (like template parsing) can integrate into React or Vue.
A: The library supports modern browsers. Ensure backdrop-filter
is supported for blur effects.
For more details or contributions, feel free to submit issues or pull requests to the project repository. Happy coding!