From 2252fe0142936b2fc129c563b94dca3a25786906 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sun, 20 Oct 2024 02:35:03 +0200 Subject: [PATCH] webserver templating seems to work fine --- Arduino/CanGrow/include/Webserver/Page_root.h | 19 +++++++++++++++++-- .../include/Webserver/Page_root_HTML.h | 10 +++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Arduino/CanGrow/include/Webserver/Page_root.h b/Arduino/CanGrow/include/Webserver/Page_root.h index beb52ba..f432f3e 100644 --- a/Arduino/CanGrow/include/Webserver/Page_root.h +++ b/Arduino/CanGrow/include/Webserver/Page_root.h @@ -29,6 +29,21 @@ #include "Page_root_HTML.h" -void WebPage_root(AsyncWebServerRequest *request) { - request->send_P(200, "text/html", Page_root_HTML); +// https://techtutorialsx.com/2018/07/23/esp32-arduino-http-server-template-processing-with-multiple-placeholders/ +String Proc_WebPage_root(const String& var) { + Serial.println(":: [Webserver:Page:root:proc] start"); + Serial.print(":: [Webserver:Page:root:proc] var: "); + Serial.println(var); + + if(var == "LOL") { + return String("omg das geht ja"); + } else if(var == "ROFL") { + return String("rooooooofl geilooooomatic! omg %)"); + } else { + return String(); + } +} + +void WebPage_root(AsyncWebServerRequest *request) { + request->send_P(200, "text/html", Page_root_HTML, Proc_WebPage_root); } diff --git a/Arduino/CanGrow/include/Webserver/Page_root_HTML.h b/Arduino/CanGrow/include/Webserver/Page_root_HTML.h index c1cde90..75807c2 100644 --- a/Arduino/CanGrow/include/Webserver/Page_root_HTML.h +++ b/Arduino/CanGrow/include/Webserver/Page_root_HTML.h @@ -29,5 +29,13 @@ const char* Page_root_HTML PROGMEM = R"( -

CanGrow>

+ + +

CanGrow

+ Hi
+ %LOL%
+ %ROFL%
+ Bye
+ + )";