mirror of
https://github.com/alexhopeoconnor/DFTE.git
synced 2026-10-04 04:28:10 +10:00
2.5 KiB
2.5 KiB
Device Framework Template Engine
DFTE streams HTML and text for ESP8266 and ESP32 without constructing a giant response in RAM. It combines PROGMEM templates, live getters, nested layouts, conditions, and iterators with request-safe asynchronous HTTP rendering.
Why use it
- Predictable memory: render fixed-size chunks instead of one large
String. - Reusable templates: keep layouts, partials, CSS, and HTML in flash.
- Live device data: resolve values from getters only when a chunk is rendered.
- Safe async responses: use one render context per HTTP request while sharing one prepared registry.
Try it
#include <TemplateEngine.h>
static const char PAGE[] PROGMEM = "<h1>%TITLE%</h1>";
Serial.begin(115200);
PlaceholderRegistry registry;
TemplateContext context;
void setup() {
registry.registerProgmemData(PSTR("%TITLE%"), PSTR("Hello DFTE"));
registry.registerProgmemTemplate(PSTR("%PAGE%"), PAGE);
context.setRegistry(®istry);
TemplateRenderer::initializeContext(context, PSTR("%PAGE%"));
}
void loop() {
uint8_t chunk[128];
if (!TemplateRenderer::isComplete(context) && !TemplateRenderer::hasError(context)) {
Serial.write(chunk, TemplateRenderer::renderNextChunk(context, chunk, sizeof(chunk)));
}
}
Featured examples
| Goal | Example |
|---|---|
| Smallest placeholder render | HelloPlaceholder |
| Layouts, partials, and conditions | NestedLayouts |
| Async HTTP streaming | StreamingAsync |
| Dashboard, iterators, and telemetry | AsyncDashboardDemo |
Install
lib_deps =
DeviceFrameworkTemplateEngine=https://github.com/alexhopeoconnor/DFTE.git#v1.1.0
PlatformIO checks out the Git ref after #; GitHub Release assets are unrelated. DFTE’s supported release targets are ESP8266 and ESP32.
Documentation
Read the documentation index for template syntax, async web responses, per-context memory sizing, examples, tests, and releases.
Development and releases
./scripts/test.sh compile --platform esp8266
./scripts/test.sh compile --platform esp32
./scripts/check-docs.sh
./scripts/prepare-release.sh vMAJOR.MINOR.PATCH --tag
Tagging repeats the board-free compile checks, validates the package, and creates a GitHub Release from the matching changelog section. It does not publish to the PlatformIO Registry or deploy firmware.