Mixing static, template and print responses
I read the Responses chapter in the docs. In a real use-case scenario I'd like to be able to mix three methods of responses:
- static: in order to have the html files on the SPIFFS
- template: in order to substitute short variables
- print: in order to generate dynamic pages on the fly
Right now I understand how to use the first and second method together:
String WebApp::processor(const String &var)
{
if (var == "NAME") return APP_NAME;
if (var == "VERSION") return APP_VERSION;
return String("");
}
void WebApp::Begin()
{
_server.serveStatic("/", SPIFFS, "/www")
.setDefaultFile("index.html")
.setTemplateProcessor(std::bind(&WebApp::processor, this, std::placeholders::_1));
// ...
}
Let's say now I have a table in the middle of my html file the must be filled server side. The best way would be to keep the structure of the file on the SPIFFS, using the template as above, but when a different placeholder is found, a different callback is called where I can print out my table. Something like:
void WebApp::processor2(AsyncResponseStream *response, const String &var)
{
if (var == "TABLE")
{
response->print("<table>");
response->print("...");
// ...
response->print("</table>");
}
}
Is it possible? How?
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.