-->
Page 1 of 1

Minimal HTML template processing library for ESP8266 Arduino

PostPosted: Sat Jan 21, 2017 3:56 pm
by wwinder
I wasn't able to find an unintrusive library to help with HTML templates and the ESP8266WebServer class, so I created one. The basic usage is similar to the template callback system in esphttpd, it also loads the template out of the SPIFFS. Here's a small example of what it looks like to use:

Code: Select allString indexProcessor(const String& key) {
  Serial.println(String("KEY IS ") + key);
  if (key == "TITLE") return "Hello World!";
  else if (key == "BODY") return "It works!";

  return "oops";
}

void handleRoot() {
  if (ESPTemplateProcessor(server).send(String("/index.html"), indexProcessor)) {
    Serial.println("SUCCESS");
  } else {
    Serial.println("FAIL");
    server.send(200, "text/plain", "page not found.");
  }
}


It's a header-only library right now on github: https://github.com/winder/ESPTemplateProcessor